.\"
.\"
.\" DO NOT MODIFY - AUTOGENERATED FROM .H FILES!
.\"
.\"
.TH LIBAIO 3 2006-02-08
.SH NAME
bufio - buffered read/write I/O interface
.SH SYNOPSIS
.B #include <libaio/bufio.h>
.sp 1
\fB\fIbufio_init(sock);\fR
.br
\fB\fIbufio_read(sock, 16, read_hook, NULL);\fR
.br
\fB\fIbufio_write(sock, 3, "hi!", NULL, NULL);\fR
.br
\fB\fIbufio_done(sock, libaio_dummy, NULL);\fR
.SH DESCRIPTION
.TP
\fBPer-socket buffers\fR
\fB\fItypedef struct {\fR
.br
\fB\fI	/* User socket handlers (we have own handlers attached to the socket\fR
.br
\fB\fI	 * itself). Note that the user handler_e is still stored in sock_t. */\fR
.br
\fB\fI	void (*handler_r)(sock_t *sock, int len, char *buf, void *data)\fR
.br
\fB\fI	void (*handler_w)(sock_t *sock, void *data)\fR
.br
\fB\fI	/* !(NULL) == destruction scheduled */\fR
.br
\fB\fI	void (*handler_d)(sock_t *sock, void *data)\fR
.br
\fB\fI	void *handler_r_data\fR
.br
\fB\fI	void *handler_w_data\fR
.br
\fB\fI	void *handler_d_data\fR
.br
\fB\fI	int winlen;			/* wanted length */\fR
.br
\fB\fI	int inblen, outblen;		/* actual length */\fR
.br
\fB\fI	char *inbuf, *outbuf;		/* buffers itselves */\fR
.br
\fB\fI} buf_t\fR
.TP
\fBBuffered I/O routines\fR
.RS

Note that these are somewhat different from the sock_t handlers. You won't
normally touch anything in the structure above directly but just tell bufio
what to do for you, and it will do it on its own and give you the requested
data when all of them arrived.
.TP
\fBbuf_t *bufio_get()\fR
This function sets up a buf_t structure. You probably will not use this
directly.

Returns pointer to the allocated structure or NULL on failure. 
.TP
\fBint bufio_init(sock_t *sock)\fR
This function sets up buffer I/O on specified socket. 

Returns 1 if ok, 0 otherwise 
.TP
\fBint bufio_read(sock_t *sock, int len, void (*handler)(sock_t *sock, int len, char *buf, void *data), void *data)\fR
This function lets you shedule read of a specified amount of data and pass
it to a specified function. Note that your handler may be called immediately
if enough data is already buffered. You cannot directly queue more reads;
if a read is already sheduled, it is cancelled and the handler is replaced.
(Cancelling does not involve touching the buffered data in any way,
of course.)

Returns 1 if ok, 0 otherwise 
.TP
\fBint bufio_write(sock_t *sock, int len, char *buf, void (*handler)(sock_t *sock, void *data), void *data)\fR
This function lets you shedule write of a specified amount of data and then
notify you back by a specified function. You can queue multiple writes, but
only the last handler will be called at the completion. You may specify
a NULL handler.

Returns 1 if ok, 0 otherwise 
.TP
\fBint bufio_done(sock_t *sock, void (*handler)(sock_t *sock, void *data), void *data)\fR
This function lets you schedule the buffers destruction. It will wait until
the current read and write is finished (no more reads and writes are
permitted) and then it will release the buffer structures and call your
function to notify you. You may NOT specify NULL handler here - use 'libaio_dummy'
instead).

Returns 1 if ok, 0 otherwise 
.TP
\fBbuf_t *bufio_del(buf_t *buf)\fR
This function will immediately release all buffer structures. 

Always returns NULL. 
.RE
.SH BUGS
None known.
.SH "SEE ALSO"
.BR libaio (7)
