iobuf/common.h

00001 /* $Id: common.h 706 2006-07-27 18:56:01Z bruce $ */
00002 #ifndef IO_BUF__COMMON__H__
00003 #define IO_BUF__COMMON__H__
00004 
00005 #include <fcntl.h>
00006 
00007 #define LF ((char)10)
00008 #define CR ((char)13)
00009 #define CRLF "\015\012"
00010 
00011 struct str;
00012 
00026 #define IOBUF_EOF 1
00027 
00028 #define IOBUF_ERROR 2
00029 
00030 #define IOBUF_TIMEOUT 4
00031 
00032 #define IOBUF_BADFLAGS 0xf
00033 
00034 #define IOBUF_SEEKABLE 0x10
00035 
00036 #define IOBUF_NEEDSCLOSE 0x20
00037 
00038 #define IOBUF_NEEDSFREE 0x40
00039 
00040 #define IOBUF_NEEDSMUNMAP 0x80
00041 extern unsigned iobuf_bufsize;
00042 
00049 struct iobuf
00050 {
00052   int fd;
00054   char* buffer;
00056   unsigned bufsize;
00058   unsigned buflen;
00060   unsigned bufstart;
00062   unsigned offset;
00064   unsigned timeout;
00066   unsigned flags;
00068   int errnum;
00069 };
00070 typedef struct iobuf iobuf;
00071 
00073 #define IOBUF_SET_ERROR(io) \
00074 do{ \
00075   io->flags |= IOBUF_ERROR; \
00076   io->errnum = errno; \
00077   return 0; \
00078 }while(0)
00079 
00080 int iobuf_init(iobuf* io, int fd, unsigned bufsize, char* buffer,
00081                unsigned flags);
00082 int iobuf_close(iobuf* io);
00084 #define iobuf_closed(io) ((io)->fd == -1)
00085 
00086 #define iobuf_error(io) ((io)->flags & IOBUF_ERROR)
00087 
00088 #define iobuf_timedout(io) ((io)->flags & IOBUF_TIMEOUT)
00089 
00090 #define iobuf_bad(io) ((io)->flags & IOBUF_BADFLAGS)
00091 int iobuf_timeout(iobuf* io, int poll_out);
00096 #endif

Generated on Mon Oct 30 15:11:13 2006 for bglibs by  doxygen 1.4.7