if (Siz == 0)
{
+ free(NewBuf);
return NULL;
}
*/
void StrBufAppendBuf(StrBuf *Buf, const StrBuf *AppendBuf, unsigned long Offset)
{
- if ((AppendBuf == NULL) || (Buf == NULL) || (AppendBuf->buf == NULL))
+ if ((AppendBuf == NULL) || (AppendBuf->buf == NULL) ||
+ (Buf == NULL) || (Buf->buf == NULL))
return;
if (Buf->BufSize - Offset < AppendBuf->BufUsed + Buf->BufUsed + 1)
*/
void StrBufCutRight(StrBuf *Buf, int nChars)
{
- if ((Buf == NULL) || (Buf->BufUsed == 0)) return;
+ if ((Buf == NULL) || (Buf->BufUsed == 0) || (Buf->buf == NULL))
+ return;
+
if (nChars >= Buf->BufUsed) {
FlushStrBuf(Buf);
return;
return ReducedBy;
}
+int StrBufExtract_tokenFromStr(StrBuf *dest, const char *Source, long SourceLen, int parmnum, char separator)
+{
+ const StrBuf Temp = {
+ (char*)Source,
+ SourceLen,
+ SourceLen,
+ 1
+#ifdef SIZE_DEBUG
+ ,
+ 0,
+ "",
+ ""
+#endif
+ };
+
+ return StrBufExtract_token(dest, &Temp, parmnum, separator);
+}
/**
* @ingroup StrBuf_Tokenizer
int a, b, len;
char hex[3];
- if (target != NULL)
- FlushStrBuf(target);
-
- if (source == NULL ||target == NULL)
+ if ((source == NULL) || (target == NULL) || (target->buf == NULL))
{
return;
}
+ if (target != NULL)
+ FlushStrBuf(target);
+
len = source->BufUsed;
for (a = 0; a < len; ++a) {
if (target->BufUsed >= target->BufSize)
if (target != NULL)
FlushStrBuf(target);
- if (source == NULL ||target == NULL)
+ if ((source == NULL) || (target == NULL) || (target->buf == NULL))
{
return;
}
const char *aptr, *ptr, *eptr;
char *optr, *xptr;
- if ((FB == NULL) || (LineBuf == NULL))
+ if ((FB == NULL) || (LineBuf == NULL) || (LineBuf->buf == NULL))
return eReadFail;
FDB->ChunkSize =
FDB->TotalSendSize = TotalSendSize;
FDB->IOB = IO;
-#ifndef LINUX_SENDFILE
+#ifndef LINUX_SPLICE
FDB->ChunkBuffer = NewStrBufPlain(NULL, TotalSendSize + 1);
#else
pipe(FDB->SplicePipe);
void FDIOBufferDelete(FDIOBuffer *FDB)
{
-#ifndef LINUX_SENDFILE
+#ifndef LINUX_SPLICE
FreeStrBuf(&FDB->ChunkBuffer);
#else
close(FDB->SplicePipe[0]);
int FileSendChunked(FDIOBuffer *FDB, const char **Err)
{
-
-#ifdef LINUX_SENDFILE
- ssize_t sent;
- sent = sendfile(FDB->IOB->fd, FDB->OtherFD, &FDB->TotalSentAlready, FDB->ChunkSendRemain);
+ 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 (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);
return sent;
}
+ FDB->PipeSize -= sent;
FDB->ChunkSendRemain -= sent;
- FDB->TotalSentAlready += sent;
- return FDB->ChunkSendRemain;
+ return sent;
#else
char *pRead;
{
ssize_t sent, pipesize;
-#ifdef LINUX_SENDFILE
+#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)
+ {
+ *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);
- 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 (sent == -1)
{
*Err = strerror(errno);
- return pipesize;
+ return sent;
}
+ FDB->PipeSize -= sent;
+ FDB->ChunkSendRemain -= sent;
+ return sent;
+#else
- sent = splice(FDB->SplicePipe[0], NULL,
- FDB->OtherFD, &FDB->TotalSentAlready,
- pipesize, SPLICE_F_MORE | SPLICE_F_MOVE);
+ sent = read(FDB->IOB->fd, FDB->ChunkBuffer->buf, FDB->ChunkSendRemain);
+ if (sent > 0) {
+ int nWritten = 0;
+ int rc;
+
+ 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;
+
+ }
+ FDB->ChunkBuffer->BufUsed = 0;
+ FDB->TotalSentAlready += sent;
+ FDB->ChunkSendRemain -= sent;
+ return FDB->ChunkSendRemain;
+ }
+ else if (sent < 0) {
+ *Err = strerror(errno);
+ return sent;
+ }
+
+#endif
+ return 0;
+}
+
+int FileMoveChunked(FDIOBuffer *FDB, const char **Err)
+{
+ 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)
+ {
+ *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);
return sent;
}
+ FDB->PipeSize -= sent;
FDB->ChunkSendRemain -= sent;
return sent;
#else
{
int len, rlen, slen;
- if (buf == NULL) {
+ if ((buf == NULL) || (buf->buf == NULL)) {
*Error = strerror(EINVAL);
return -1;
}
struct timeval tv;
fd_set rfds;
- if ((Buf == NULL) || (*fd == -1))
+ if ((Buf == NULL) || (Buf->buf == NULL) || (*fd == -1))
{
*Error = ErrRBLF_BLOBPreConditionFailed;
return -1;
if ((Buf == NULL) ||
(*Ptr == StrBufNOTNULL) ||
- (LineBuf == NULL))
+ (LineBuf == NULL)||
+ (LineBuf->buf == NULL))
{
*Ptr = StrBufNOTNULL;
return 0;