- splice tends to break. let the choice to the admin to enable it. Default to stable copying shit to userspace back and forth.
+extern int EnableSplice;
extern int BaseStrBufSize;
char *libcitadel_version_string(void) {
return "libcitadel(unnumbered)";
extern int BaseStrBufSize;
char *libcitadel_version_string(void) {
return "libcitadel(unnumbered)";
void StartLibCitadel(size_t basesize)
{
void StartLibCitadel(size_t basesize)
{
BaseStrBufSize = basesize;
BaseStrBufSize = basesize;
+ Splice = getenv("LIBCITADEL_ENABLE_SPLICE");
+ if (Splice != NULL)
+ EnableSplice = atol(Splice);
}
void ShutDownLibCitadel(void)
}
void ShutDownLibCitadel(void)
const Bytef * source, uLong sourceLen, int level);
#endif
int BaseStrBufSize = 64;
const Bytef * source, uLong sourceLen, int level);
#endif
int BaseStrBufSize = 64;
const char *StrBufNOTNULL = ((char*) NULL) - 1;
const char *StrBufNOTNULL = ((char*) NULL) - 1;
FDB->ChunkSize =
FDB->TotalSendSize = TotalSendSize;
FDB->IOB = IO;
FDB->ChunkSize =
FDB->TotalSendSize = TotalSendSize;
FDB->IOB = IO;
-#ifndef LINUX_SPLICE
- FDB->ChunkBuffer = NewStrBufPlain(NULL, TotalSendSize + 1);
-#else
- pipe(FDB->SplicePipe);
+#ifdef LINUX_SPLICE
+ if (EnableSplice)
+ pipe(FDB->SplicePipe);
+ else
+ FDB->ChunkBuffer = NewStrBufPlain(NULL, TotalSendSize + 1);
+
FDB->OtherFD = FD;
}
void FDIOBufferDelete(FDIOBuffer *FDB)
{
FDB->OtherFD = FD;
}
void FDIOBufferDelete(FDIOBuffer *FDB)
{
-#ifndef LINUX_SPLICE
- FreeStrBuf(&FDB->ChunkBuffer);
-#else
- close(FDB->SplicePipe[0]);
- close(FDB->SplicePipe[1]);
-
+#ifdef LINUX_SPLICE
+ if (EnableSplice)
+ {
+ close(FDB->SplicePipe[0]);
+ close(FDB->SplicePipe[1]);
+ }
+ else
+ FreeStrBuf(&FDB->ChunkBuffer);
+
close(FDB->OtherFD);
memset(FDB, 0, sizeof(FDIOBuffer));
}
close(FDB->OtherFD);
memset(FDB, 0, sizeof(FDIOBuffer));
}
{
ssize_t sent, pipesize;
#ifdef LINUX_SPLICE
{
ssize_t sent, pipesize;
#ifdef LINUX_SPLICE
- if (FDB->PipeSize == 0)
- pipesize = splice(FDB->OtherFD,
- &FDB->TotalSentAlready,
- FDB->SplicePipe[1],
- NULL,
- FDB->ChunkSendRemain,
- SPLICE_F_MOVE);
+ if (FDB->PipeSize == 0)
+ {
+ pipesize = splice(FDB->OtherFD,
+ &FDB->TotalSentAlready,
+ FDB->SplicePipe[1],
+ NULL,
+ FDB->ChunkSendRemain,
+ SPLICE_F_MOVE);
+ if (pipesize == -1)
+ {
+ *Err = strerror(errno);
+ return pipesize;
+ }
+ FDB->PipeSize = pipesize;
+ }
+ sent = splice(FDB->SplicePipe[0],
+ NULL,
+ FDB->IOB->fd,
+ NULL,
+ FDB->PipeSize,
+ SPLICE_F_MORE | SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
+ if (sent == -1)
{
*Err = strerror(errno);
{
*Err = strerror(errno);
- FDB->PipeSize = pipesize;
- }
- sent = splice(FDB->SplicePipe[0],
- NULL,
- FDB->IOB->fd,
- NULL,
- FDB->PipeSize,
- SPLICE_F_MORE | SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
- if (sent == -1)
- {
- *Err = strerror(errno);
+ FDB->PipeSize -= sent;
+ FDB->ChunkSendRemain -= sent;
- FDB->PipeSize -= sent;
- FDB->ChunkSendRemain -= sent;
- return sent;
-#else
-
- char *pRead;
- long nRead = 0;
-
- pRead = FDB->ChunkBuffer->buf;
- while ((FDB->ChunkBuffer->BufUsed < FDB->TotalSendSize) && (nRead >= 0))
- nRead = read(FDB->OtherFD, pRead, FDB->TotalSendSize - FDB->ChunkBuffer->BufUsed);
- if (nRead > 0) {
- FDB->ChunkBuffer->BufUsed += nRead;
- FDB->ChunkBuffer->buf[FDB->ChunkBuffer->BufUsed] = '\0';
- }
- else if (nRead == 0) {}
- else return nRead;
+ char *pRead;
+ long nRead = 0;
+
+ pRead = FDB->ChunkBuffer->buf;
+ while ((FDB->ChunkBuffer->BufUsed < FDB->TotalSendSize) && (nRead >= 0))
+ {
+ nRead = read(FDB->OtherFD, pRead, FDB->TotalSendSize - FDB->ChunkBuffer->BufUsed);
+ if (nRead > 0) {
+ FDB->ChunkBuffer->BufUsed += nRead;
+ FDB->ChunkBuffer->buf[FDB->ChunkBuffer->BufUsed] = '\0';
+ }
+ else if (nRead == 0) {}
+ else return nRead;
- nRead = write(FDB->IOB->fd, FDB->ChunkBuffer->buf + FDB->TotalSentAlready, FDB->ChunkSendRemain);
+ nRead = write(FDB->IOB->fd, FDB->ChunkBuffer->buf + FDB->TotalSentAlready, FDB->ChunkSendRemain);
- if (nRead >= 0) {
- FDB->TotalSentAlready += nRead;
- FDB->ChunkSendRemain -= nRead;
- return FDB->ChunkSendRemain;
- }
- else {
- return nRead;
+ if (nRead >= 0) {
+ FDB->TotalSentAlready += nRead;
+ FDB->ChunkSendRemain -= nRead;
+ return FDB->ChunkSendRemain;
+ }
+ else {
+ return nRead;
+ }
}
int FileRecvChunked(FDIOBuffer *FDB, const char **Err)
}
int FileRecvChunked(FDIOBuffer *FDB, const char **Err)
ssize_t sent, pipesize;
#ifdef LINUX_SPLICE
ssize_t sent, pipesize;
#ifdef LINUX_SPLICE
- if (FDB->PipeSize == 0)
- pipesize = splice(FDB->IOB->fd,
- NULL,
- FDB->SplicePipe[1],
- NULL,
- FDB->ChunkSendRemain,
- SPLICE_F_MORE | SPLICE_F_MOVE|SPLICE_F_NONBLOCK);
-
- if (pipesize == -1)
+ if (FDB->PipeSize == 0)
- *Err = strerror(errno);
- return pipesize;
+ pipesize = splice(FDB->IOB->fd,
+ NULL,
+ FDB->SplicePipe[1],
+ NULL,
+ FDB->ChunkSendRemain,
+ SPLICE_F_MORE | SPLICE_F_MOVE|SPLICE_F_NONBLOCK);
+
+ if (pipesize == -1)
+ {
+ *Err = strerror(errno);
+ return pipesize;
+ }
+ FDB->PipeSize = pipesize;
- FDB->PipeSize = pipesize;
- }
- sent = splice(FDB->SplicePipe[0],
- NULL,
- FDB->OtherFD,
- &FDB->TotalSentAlready,
- FDB->PipeSize,
- SPLICE_F_MORE | SPLICE_F_MOVE);
-
- if (sent == -1)
- {
- *Err = strerror(errno);
+ sent = splice(FDB->SplicePipe[0],
+ NULL,
+ FDB->OtherFD,
+ &FDB->TotalSentAlready,
+ FDB->PipeSize,
+ SPLICE_F_MORE | SPLICE_F_MOVE);
+
+ if (sent == -1)
+ {
+ *Err = strerror(errno);
+ return sent;
+ }
+ FDB->PipeSize -= sent;
+ FDB->ChunkSendRemain -= sent;
- FDB->PipeSize -= sent;
- FDB->ChunkSendRemain -= sent;
- return sent;
-#else
-
- sent = read(FDB->IOB->fd, FDB->ChunkBuffer->buf, FDB->ChunkSendRemain);
- if (sent > 0) {
- int nWritten = 0;
- int rc;
+ else
+#endif
+ {
+ sent = read(FDB->IOB->fd, FDB->ChunkBuffer->buf, FDB->ChunkSendRemain);
+ if (sent > 0) {
+ int nWritten = 0;
+ int rc;
- FDB->ChunkBuffer->BufUsed = sent;
+ FDB->ChunkBuffer->BufUsed = sent;
- while (nWritten < FDB->ChunkBuffer->BufUsed) {
- rc = write(FDB->OtherFD, FDB->ChunkBuffer->buf + nWritten, FDB->ChunkBuffer->BufUsed - nWritten);
- if (rc < 0) {
- *Err = strerror(errno);
- return rc;
- }
- nWritten += rc;
+ while (nWritten < FDB->ChunkBuffer->BufUsed) {
+ rc = write(FDB->OtherFD, FDB->ChunkBuffer->buf + nWritten, FDB->ChunkBuffer->BufUsed - nWritten);
+ if (rc < 0) {
+ *Err = strerror(errno);
+ return rc;
+ }
+ nWritten += rc;
+ }
+ FDB->ChunkBuffer->BufUsed = 0;
+ FDB->TotalSentAlready += sent;
+ FDB->ChunkSendRemain -= sent;
+ return FDB->ChunkSendRemain;
- FDB->ChunkBuffer->BufUsed = 0;
- FDB->TotalSentAlready += sent;
- FDB->ChunkSendRemain -= sent;
- return FDB->ChunkSendRemain;
- }
- else if (sent < 0) {
- *Err = strerror(errno);
- return sent;
+ else if (sent < 0) {
+ *Err = strerror(errno);
+ return sent;
+ }
+ return 0;
}
int FileMoveChunked(FDIOBuffer *FDB, const char **Err)
}
int FileMoveChunked(FDIOBuffer *FDB, const char **Err)
ssize_t sent, pipesize;
#ifdef LINUX_SPLICE
ssize_t sent, pipesize;
#ifdef LINUX_SPLICE
- if (FDB->PipeSize == 0)
- pipesize = splice(FDB->IOB->fd,
- &FDB->TotalReadAlready,
- FDB->SplicePipe[1],
- NULL,
- FDB->ChunkSendRemain,
- SPLICE_F_MORE | SPLICE_F_MOVE|SPLICE_F_NONBLOCK);
-
- if (pipesize == -1)
+ if (FDB->PipeSize == 0)
+ {
+ pipesize = splice(FDB->IOB->fd,
+ &FDB->TotalReadAlready,
+ FDB->SplicePipe[1],
+ NULL,
+ FDB->ChunkSendRemain,
+ SPLICE_F_MORE | SPLICE_F_MOVE|SPLICE_F_NONBLOCK);
+
+ if (pipesize == -1)
+ {
+ *Err = strerror(errno);
+ return pipesize;
+ }
+ FDB->PipeSize = pipesize;
+ }
+
+ sent = splice(FDB->SplicePipe[0],
+ NULL,
+ FDB->OtherFD,
+ &FDB->TotalSentAlready,
+ FDB->PipeSize,
+ SPLICE_F_MORE | SPLICE_F_MOVE);
+
+ if (sent == -1)
{
*Err = strerror(errno);
{
*Err = strerror(errno);
- FDB->PipeSize = pipesize;
- }
-
- sent = splice(FDB->SplicePipe[0],
- NULL,
- FDB->OtherFD,
- &FDB->TotalSentAlready,
- FDB->PipeSize,
- SPLICE_F_MORE | SPLICE_F_MOVE);
-
- if (sent == -1)
- {
- *Err = strerror(errno);
+ FDB->PipeSize -= sent;
+ FDB->ChunkSendRemain -= sent;
- FDB->PipeSize -= sent;
- FDB->ChunkSendRemain -= sent;
- return sent;
-#else
-
- sent = read(FDB->IOB->fd, FDB->ChunkBuffer->buf, FDB->ChunkSendRemain);
- if (sent > 0) {
- int nWritten = 0;
- int rc;
+ else
+#endif
+ {
+ sent = read(FDB->IOB->fd, FDB->ChunkBuffer->buf, FDB->ChunkSendRemain);
+ if (sent > 0) {
+ int nWritten = 0;
+ int rc;
- FDB->ChunkBuffer->BufUsed = sent;
+ FDB->ChunkBuffer->BufUsed = sent;
- while (nWritten < FDB->ChunkBuffer->BufUsed) {
- rc = write(FDB->OtherFD, FDB->ChunkBuffer->buf + nWritten, FDB->ChunkBuffer->BufUsed - nWritten);
- if (rc < 0) {
- *Err = strerror(errno);
- return rc;
- }
- nWritten += rc;
+ while (nWritten < FDB->ChunkBuffer->BufUsed) {
+ rc = write(FDB->OtherFD, FDB->ChunkBuffer->buf + nWritten, FDB->ChunkBuffer->BufUsed - nWritten);
+ if (rc < 0) {
+ *Err = strerror(errno);
+ return rc;
+ }
+ nWritten += rc;
+ }
+ FDB->ChunkBuffer->BufUsed = 0;
+ FDB->TotalSentAlready += sent;
+ FDB->ChunkSendRemain -= sent;
+ return FDB->ChunkSendRemain;
- FDB->ChunkBuffer->BufUsed = 0;
- FDB->TotalSentAlready += sent;
- FDB->ChunkSendRemain -= sent;
- return FDB->ChunkSendRemain;
- }
- else if (sent < 0) {
- *Err = strerror(errno);
- return sent;
+ else if (sent < 0) {
+ *Err = strerror(errno);
+ return sent;
+ }
+ return 0;
}
eReadState WriteIOBAlreadyRead(FDIOBuffer *FDB, const char **Error)
}
eReadState WriteIOBAlreadyRead(FDIOBuffer *FDB, const char **Error)