iobuf_common.h
#ifndef IO_BUF__COMMON__H__
#define IO_BUF__COMMON__H__
#include <fcntl.h>
#define LF ((char)10)
#define CR ((char)13)
#define CRLF "\015\012"
struct str;
#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
extern unsigned iobuf_bufsize;
struct iobuf
{
int fd;
char* buffer;
unsigned bufsize;
unsigned buflen;
unsigned bufstart;
unsigned offset;
unsigned timeout;
unsigned flags;
int errnum;
};
typedef struct iobuf iobuf;
#define IOBUF_SET_ERROR(io) \
do{ \
io->flags |= IOBUF_ERROR; \
io->errnum = errno; \
return 0; \
}while(0)
int iobuf_init(iobuf* io, int fd, unsigned bufsize, char* buffer,
unsigned flags);
int iobuf_close(iobuf* 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)
int iobuf_timeout(iobuf* io, int poll_out);
#endif
iobuf::bufstart
unsigned bufstart
Definition: iobuf_common.h:59
iobuf::buffer
char * buffer
Definition: iobuf_common.h:53
iobuf::timeout
unsigned timeout
Definition: iobuf_common.h:63
iobuf::buflen
unsigned buflen
Definition: iobuf_common.h:57
iobuf_timeout
int iobuf_timeout(iobuf *io, int poll_out)
Definition: iobuf_timeout.c:6
iobuf_init
int iobuf_init(iobuf *io, int fd, unsigned bufsize, char *buffer, unsigned flags)
Definition: iobuf_init.c:19
iobuf::errnum
int errnum
Definition: iobuf_common.h:67
iobuf_close
int iobuf_close(iobuf *io)
Definition: iobuf_close.c:8
str
Definition: str.h:30
iobuf::fd
int fd
Definition: iobuf_common.h:51
iobuf
Definition: iobuf_common.h:48
iobuf::flags
unsigned flags
Definition: iobuf_common.h:65
iobuf_bufsize
unsigned iobuf_bufsize
Definition: iobuf_init.c:8
iobuf::bufsize
unsigned bufsize
Definition: iobuf_common.h:55
iobuf::offset
unsigned offset
Definition: iobuf_common.h:61