iocache.h File Reference

I/O cache function declarations. More...

#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>

Go to the source code of this file.



typedef struct iocache iocache
void iocache_destroy (iocache *ioc)
 Destroys an iocache object, freeing all memory allocated to it.
void iocache_reset (iocache *ioc)
 Resets an iocache struct, discarding all data in it without free()'ing any memory.
int iocache_resize (iocache *ioc, unsigned long new_size)
 Resizes the buffer in an io cache.
int iocache_grow (iocache *ioc, unsigned long increment)
 Grows an iocache object This uses iocache_resize() internally.
unsigned long iocache_size (iocache *ioc)
 Returns the total size of the io cache.
unsigned long iocache_capacity (iocache *ioc)
 Returns remaining read capacity of the io cache.
unsigned long iocache_available (iocache *ioc)
 Return the amount of unread but stored data in the io cache.
char * iocache_use_size (iocache *ioc, unsigned long size)
 Use a chunk of data from iocache based on size.
char * iocache_use_delim (iocache *ioc, const char *delim, size_t delim_len, unsigned long *size)
 Use a chunk of data from iocache based on delimiter.
int iocache_unuse_size (iocache *ioc, unsigned long size)
 Forget that a specified number of bytes have been used.
iocache * iocache_create (unsigned long size)
 Creates the iocache object, initializing it with the given size.
int iocache_read (iocache *ioc, int fd)
 Read data into the iocache buffer.
int iocache_add (iocache *ioc, char *buf, unsigned int len)
 Add data to the iocache buffer The data is copied, so it can safely be taken from the stack in a function that returns before the data is used.
int iocache_sendto (iocache *ioc, int fd, char *buf, unsigned int len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
 Like sendto(), but sends all cached data prior to the requested.

Detailed Description

I/O cache function declarations.

The I/O cache library is useful for reading large chunks of data from sockets and utilizing parts of that data based on either size or a magic delimiter.


Function Documentation

int iocache_add ( iocache *  ioc,
char *  buf,
unsigned int  len 
)

Add data to the iocache buffer The data is copied, so it can safely be taken from the stack in a function that returns before the data is used.

If the io cache is too small to hold the data, -1 will be returned.

Parameters:
[in] ioc The io cache to add to
[in] buf Pointer to the data we should add
[in] len Length (in bytes) of data pointed to by buf
Returns:
iocache_available(ioc) on success, -1 on errors
unsigned long iocache_available ( iocache *  ioc  ) 

Return the amount of unread but stored data in the io cache.

Parameters:
ioc The io cache to operate on
Returns:
Number of bytes available to read
unsigned long iocache_capacity ( iocache *  ioc  ) 

Returns remaining read capacity of the io cache.

Parameters:
ioc The io cache to operate on
Returns:
The number of bytes available to read, or -1 if ioc is null, -2 if the buffer is null, or -2 if the buffer size is <= 0
iocache* iocache_create ( unsigned long  size  ) 

Creates the iocache object, initializing it with the given size.

Parameters:
size Initial size of the iocache buffer
Returns:
Pointer to a valid iocache object
void iocache_destroy ( iocache *  ioc  ) 

Destroys an iocache object, freeing all memory allocated to it.

Parameters:
ioc The iocache object to destroy
int iocache_grow ( iocache *  ioc,
unsigned long  increment 
)

Grows an iocache object This uses iocache_resize() internally.

Parameters:
[in] ioc The iocache to grow
[in] increment How much to increase it
Returns:
0 on success, -1 on errors
int iocache_read ( iocache *  ioc,
int  fd 
)

Read data into the iocache buffer.

Parameters:
ioc The io cache we should read into
fd The filedescriptor we should read from
Returns:
The number of bytes read on success. < 0 on errors
void iocache_reset ( iocache *  ioc  ) 

Resets an iocache struct, discarding all data in it without free()'ing any memory.

Parameters:
[in] ioc The iocache struct to reset
int iocache_resize ( iocache *  ioc,
unsigned long  new_size 
)

Resizes the buffer in an io cache.

Parameters:
ioc The io cache to resize
new_size The new size of the io cache
Returns:
0 on success, -1 on errors
int iocache_sendto ( iocache *  ioc,
int  fd,
char *  buf,
unsigned int  len,
int  flags,
const struct sockaddr *  dest_addr,
socklen_t  addrlen 
)

Like sendto(), but sends all cached data prior to the requested.

Parameters:
[in] ioc The iocache to send, or cache data in
[in] fd The file descriptor to send to
[in] buf Pointer to the data to send
[in] len Length (in bytes) of data to send
[in] flags Flags passed to sendto(2)
[in] dest_addr Destination address
[in] addrlen size (in bytes) of dest_addr
Returns:
bytes sent on success, -ERRNO on errors
unsigned long iocache_size ( iocache *  ioc  ) 

Returns the total size of the io cache.

Parameters:
[in] ioc The iocache to inspect
Returns:
The size of the io cache. If ioc is null, 0 is returned
int iocache_unuse_size ( iocache *  ioc,
unsigned long  size 
)

Forget that a specified number of bytes have been used.

Parameters:
ioc The io cache that you want to un-use data in
size The number of bytes you want to forget you've seen
Returns:
-1 if there was an error, 0 otherwise.
char* iocache_use_delim ( iocache *  ioc,
const char *  delim,
size_t  delim_len,
unsigned long *  size 
)

Use a chunk of data from iocache based on delimiter.

The caller must take care not to write beyond the end of the requested buffer, if any is returned, or Bad Things(tm) will happen.

Parameters:
ioc The io cache to use data from
delim The delimiter
delim_len Length of the delimiter
size Length of the returned buffer
Returns:
NULL on errors (delimiter not found, insufficient data). pointer on success
char* iocache_use_size ( iocache *  ioc,
unsigned long  size 
)

Use a chunk of data from iocache based on size.

The caller must take care not to write beyond the end of the requested buffer, or Bad Things(tm) will happen.

Parameters:
ioc The io cache we should use data from
size The size of the data we want returned
Returns:
NULL on errors (insufficient data, fe). pointer on success
 All Data Structures Files Functions Variables Typedefs Defines

Generated on 5 Feb 2019 for Nagios by  doxygen 1.6.1