iobuf: I/O Buffer Management

Data Structures

struct  iobuf

Status Flags

unsigned iobuf_bufsize
#define IOBUF_EOF   1
#define IOBUF_ERROR   2
#define IOBUF_TIMEOUT   4
#define IOBUF_BADFLAGS   0xf
#define IOBUF_SEEKABLE   0x10
#define IOBUF_NEEDSCLOSE   0x20
#define IOBUF_NEEDSFREE   0x40
#define IOBUF_NEEDSMUNMAP   0x80


typedef struct iobuf iobuf
int iobuf_init (iobuf *io, int fd, unsigned bufsize, char *buffer, unsigned flags)
int iobuf_close (iobuf *io)
int iobuf_timeout (iobuf *io, int poll_out)
#define IOBUF_SET_ERROR(io)
#define iobuf_closed(io)   ((io)->fd == -1)
#define iobuf_error(io)   ((io)->flags & IOBUF_ERROR)
#define iobuf_timedout(io)   ((io)->flags & IOBUF_TIMEOUT)
#define iobuf_bad(io)   ((io)->flags & IOBUF_BADFLAGS)

Mass copying functions.

int iobuf_copy (ibuf *in, obuf *out)
int iobuf_copyflush (ibuf *in, obuf *out)
int ibuf_copytofd (ibuf *in, int out)
int obuf_copyfromfd (int in, obuf *out)

Detailed Description

Calling Convention
Unless otherwise specified, the return value is non-zero (true) if the entire requested operation completed, and 0 (false) otherwise.

Define Documentation

#define iobuf_bad ( io   )     ((io)->flags & IOBUF_BADFLAGS)

True if the iobuf is in a "bad" state.

#define IOBUF_BADFLAGS   0xf

Mask of all the error type flags.

#define iobuf_closed ( io   )     ((io)->fd == -1)

True if the iobuf has been closed.

#define IOBUF_EOF   1

Reading reached end of file.

#define iobuf_error ( io   )     ((io)->flags & IOBUF_ERROR)

True if the iobuf has an error flag.

#define IOBUF_ERROR   2

The iobuf has encountered an error.

#define IOBUF_NEEDSCLOSE   0x20

The file descriptor needs to be closed.

#define IOBUF_NEEDSFREE   0x40

The buffer needs to be deallocated with free

#define IOBUF_NEEDSMUNMAP   0x80

The buffer needs to be deallocated with munmap

#define IOBUF_SEEKABLE   0x10

lseek is possible on the file descriptor.

#define IOBUF_SET_ERROR ( io   ) 


do{ \
  io->flags |= IOBUF_ERROR; \
  io->errnum = errno; \
  return 0; \
Set the error flag, save errno, and return false.

#define iobuf_timedout ( io   )     ((io)->flags & IOBUF_TIMEOUT)

True if the input or output to the iobuf previously timed out.

#define IOBUF_TIMEOUT   4

The timeout expired before the read or write could be completed.

Function Documentation

int ibuf_copytofd ( ibuf in,
int  out 

Copy all the data from an ibuf to an output file descriptor.

int iobuf_close ( iobuf io  ) 

Close an iobuf and deallocate the buffer.

int iobuf_copy ( ibuf in,
obuf out 

Copy all the data from an ibuf to an obuf.

int iobuf_copyflush ( ibuf in,
obuf out 

Copy all the data from an ibuf to an obuf, and flush the obuf after writing is completed.

int iobuf_init ( iobuf io,
int  fd,
unsigned  bufsize,
char *  buffer,
unsigned  flags 

Initialize an iobuf structure.

int iobuf_timeout ( iobuf io,
int  poll_out 

Wait for a file descriptor to be ready for reading or writing.

int obuf_copyfromfd ( int  in,
obuf out 

Copy all the data from an input file descriptor to an obuf.

Variable Documentation

unsigned iobuf_bufsize

The default iobuf buffer size, defaults to 8192.

Generated on Thu Feb 19 11:11:50 2009 for bglibs by  doxygen 1.5.4