Nagios 4.4.14
Dev docs for Nagios core and neb-module hackers
|
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. | |
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.
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.
[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 |
unsigned long iocache_available | ( | iocache * | ioc | ) |
Return the amount of unread but stored data in the io cache.
ioc | The io cache to operate on |
unsigned long iocache_capacity | ( | iocache * | ioc | ) |
Returns remaining read capacity of the io cache.
ioc | The io cache to operate on |
iocache * iocache_create | ( | unsigned long | size | ) |
Creates the iocache object, initializing it with the given size.
size | Initial size of the iocache buffer |
void iocache_destroy | ( | iocache * | ioc | ) |
Destroys an iocache object, freeing all memory allocated to it.
ioc | The iocache object to destroy |
int iocache_grow | ( | iocache * | ioc, |
unsigned long | increment | ||
) |
Grows an iocache object This uses iocache_resize() internally.
[in] | ioc | The iocache to grow |
[in] | increment | How much to increase it |
int iocache_read | ( | iocache * | ioc, |
int | fd | ||
) |
Read data into the iocache buffer.
ioc | The io cache we should read into |
fd | The filedescriptor we should read from |
void iocache_reset | ( | iocache * | ioc | ) |
Resets an iocache struct, discarding all data in it without free()'ing any memory.
[in] | ioc | The iocache struct to reset |
int iocache_resize | ( | iocache * | ioc, |
unsigned long | new_size | ||
) |
Resizes the buffer in an io cache.
ioc | The io cache to resize |
new_size | The new size of the io cache |
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.
[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 |
unsigned long iocache_size | ( | iocache * | ioc | ) |
Returns the total size of the io cache.
[in] | ioc | The iocache to inspect |
int iocache_unuse_size | ( | iocache * | ioc, |
unsigned long | size | ||
) |
Forget that a specified number of bytes have been used.
ioc | The io cache that you want to un-use data in |
size | The number of bytes you want to forget you've seen |
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.
ioc | The io cache to use data from |
delim | The delimiter |
delim_len | Length of the delimiter |
size | Length of the returned buffer |
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.
ioc | The io cache we should use data from |
size | The size of the data we want returned |