bglibs
iobuf_common.h
1 #ifndef IO_BUF__COMMON__H__
2 #define IO_BUF__COMMON__H__
3 
4 #include <fcntl.h>
5 
6 #define LF ((char)10)
7 #define CR ((char)13)
8 #define CRLF "\015\012"
9 
10 struct str;
11 
25 #define IOBUF_EOF 1
26 
27 #define IOBUF_ERROR 2
28 
29 #define IOBUF_TIMEOUT 4
30 
31 #define IOBUF_BADFLAGS 0xf
32 
33 #define IOBUF_SEEKABLE 0x10
34 
35 #define IOBUF_NEEDSCLOSE 0x20
36 
37 #define IOBUF_NEEDSFREE 0x40
38 
39 #define IOBUF_NEEDSMUNMAP 0x80
40 extern unsigned iobuf_bufsize;
41 
48 struct iobuf
49 {
51  int fd;
53  char* buffer;
55  unsigned bufsize;
57  unsigned buflen;
59  unsigned bufstart;
61  unsigned offset;
63  unsigned timeout;
65  unsigned flags;
67  int errnum;
68 };
69 typedef struct iobuf iobuf;
70 
72 #define IOBUF_SET_ERROR(io) \
73 do{ \
74  io->flags |= IOBUF_ERROR; \
75  io->errnum = errno; \
76  return 0; \
77 }while(0)
78 
79 int iobuf_init(iobuf* io, int fd, unsigned bufsize, char* buffer,
80  unsigned flags);
81 int iobuf_close(iobuf* io);
83 #define iobuf_closed(io) ((io)->fd == -1)
84 
85 #define iobuf_error(io) ((io)->flags & IOBUF_ERROR)
86 
87 #define iobuf_timedout(io) ((io)->flags & IOBUF_TIMEOUT)
88 
89 #define iobuf_bad(io) ((io)->flags & IOBUF_BADFLAGS)
90 int iobuf_timeout(iobuf* io, int poll_out);
95 #endif
unsigned bufstart
Definition: iobuf_common.h:59
char * buffer
Definition: iobuf_common.h:53
unsigned timeout
Definition: iobuf_common.h:63
unsigned buflen
Definition: iobuf_common.h:57
int iobuf_timeout(iobuf *io, int poll_out)
Definition: iobuf_timeout.c:6
int iobuf_init(iobuf *io, int fd, unsigned bufsize, char *buffer, unsigned flags)
Definition: iobuf_init.c:19
int errnum
Definition: iobuf_common.h:67
int iobuf_close(iobuf *io)
Definition: iobuf_close.c:8
Definition: str.h:30
int fd
Definition: iobuf_common.h:51
Definition: iobuf_common.h:48
unsigned flags
Definition: iobuf_common.h:65
unsigned iobuf_bufsize
Definition: iobuf_init.c:8
unsigned bufsize
Definition: iobuf_common.h:55
unsigned offset
Definition: iobuf_common.h:61