Home

Traffic Server Software Developers Kit

INKIOBufferWrite

Appends the specified number of bytes from a particular buffer to the IO buffer.

Prototype

int INKIOBufferWrite (INKIOBuffer bufp, const char *buf, int len)

Arguments

INKIOBuffer bufp is the target IOBuffer that receives the data.

const char *buf is the buffer that contains the data.

int len is the length of the data to write.

Description

This function appends data from *buf to IOBuffer bufp; the length of data being appended is specified in len. The returned value is the actual length of data being appended.

Example

INKIOBufferWrite offers the same functionality as the deprecated functions INKIOBufferAppend, INKIOBufferDataCreate, and INKIOBufferBlockCreate. To append the content of a buffer buf of size len into an IOBuffer, we recommend using INKIOBufferWrite. It has the following prototype:

int INKIOBufferWrite (INKIOBuffer bufp, const char *buf, int len); 

The equivalent of this API in SDK2.0 is the following snippet of code: 
 INKIOBufferBlock block; 
 int avail, ndone, ntodo, towrite; 
 char *ptr_block; 

 ndone = 0; 
 ntodo = len; 
 while (ntodo > 0) { 
      /* INKIOBufferStart allocates more blocks if required */ 
      block = INKIOBufferStart(bufp); 
      ptr_block = INKIOBufferBlockWriteStart (block, &avail); 
      towrite = min(ntodo, avail); 
      memcpy (ptr_block, buf+ndone, towrite); 
      INKIOBufferProduce(bufp, towrite); 
      ntodo -= towrite; 
      ndone += towrite; 
} 
 
Returns

The length of data copied if the API call is successful.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.