iobuffer.h revision d2f5aacd3d549c3d39dae41b6522d585244b016d
#ifndef __IOBUFFER_H
#define __IOBUFFER_H
#include "ioloop.h"
#define IO_BUFFER_MIN_SIZE 512
struct _IOBuffer {
int fd;
int buf_errno; /* set when write() or read() failed. */
/* private: */
int priority;
int timeout_msecs;
void *timeout_context;
void *flush_context;
unsigned char *buffer;
next call to io_buffer_next_line() */
};
/* Create an I/O buffer. It can be used for either sending or receiving data,
NEVER BOTH AT SAME TIME. */
/* Read the file by mmap()ing it in blocks. stop_offset specifies where to
stop reading, or 0 to end of file. */
/* Destroy a buffer. */
The data already in buffer can be used, and the remaining output buffer
will be sent. */
/* Reset all pointers so that the buffer looks empty, the actual data is
not touched and can be used. */
/* Change the memory pool used by the buffer. Data already in
buffer will be transferred to new buffer. */
/* Change the maximum size for buffer to grow. */
/* Change buffer's blocking state. The blocking state in fd itself isn't
changed, and it's not needed to be blocking. This affects two things:
When buffer reaches max_size, it will block until all the data has been
sent or timeout has been reached. Setting max_size to 0 disables this
(default). Setting timeout_msecs to 0 may block infinitely, or until
socket is closed.
Sets the timeout for io_buffer_read_blocking(). If max_size is non-zero,
it acts the same as io_buffer_set_max_size().
timeout_func is called with both cases when timeout occurs.
*/
void *context);
/* Set TCP_CORK on if supported, ie. don't send out partial frames.
io_buffer_send_flush() removes the cork. */
/* Returns 1 if all was ok, -1 if disconnected, -2 if buffer is full */
/* Send data from input buffer to output buffer using the fastest
possible method. Returns 1 if all sent or -1 if disconnected.
Note that this function may block. */
/* Flush the output buffer, blocks until all is sent. If
io_buffer_set_send_blocking() is called, it's timeout settings are used. */
/* Call specified function when the whole transmit buffer has been sent.
If the buffer is empty already, the function will be called immediately.
The function will be called only once. */
void *context);
/* Returns number of bytes read if read was ok,
-1 if disconnected / EOF, -2 if the buffer is full */
/* Like io_buffer_read(), but don't read more than specified size. */
/* Blocking read, doesn't return until at least one byte is read, or until
socket is disconnected or timeout has occured. Note that the fd must be
nonblocking, or the timeout doesn't work. If you don't want limit size,
set it to (size_t)-1. Returns number of bytes read, or -1 if error. */
/* Skip forward a number of bytes */
/* Seek to specified position from beginning of file. This works only for
files. Returns TRUE if successful. */
/* Returns the next line from input buffer, or NULL if more data is needed
to make a full line. NOTE: call to io_buffer_read() invalidates the
returned data. */
/* Returns pointer to beginning of data in buffer,
or NULL if there's no data. */
/* Like io_buffer_get_data(), but read it when needed. There always must be
more than `threshold' bytes in buffer. Returns 1 if data was read, 0 if
read was interrupted or nonblocking, -1 if EOF / error */
/* Returns a pointer to buffer wanted amount of space,
or NULL if size is too big. */
/* Send data saved to buffer from io_buffer_get_space().
Returns -1 if disconnected. */
/* Put data to buffer as if it was received.
Returns 1 if successful, -2 if buffer isn't big enough. */
/* Returns TRUE if there's nothing in buffer. */
#endif