libevent patch required for SMTP test
[ioevent.git] / EvBufferEvent.hpp
blob21565a4366481a2fb4c85b435997d4ef2c0b8b98
1 #ifndef _EV_BUFFER_EVENT__HPP_
2 #define _EV_BUFFER_EVENT__HPP_
4 #include <EvBufferEventInternal.hpp>
7 struct EvBufferEvent : EvBufferEventInternal
10 /// C read/write callback function used in the C evbuffer API.
11 typedef void (*readwritecb)(struct bufferevent *, void *);
13 /// C error callback function used in the C evbuffer API.
14 typedef void (*errorcb)(struct bufferevent *, short, void *);
16 // TODO: EvBufferEvent(int fd, ...) throw(...) { ... }
18 // Future: to be deprecated by EvBufferEvent(int fd, ...) throw(...)
19 /* public: for now */
20 /**
21 * Constructor to setup callbacks
23 EvBufferEvent(readwritecb readcb, readwritecb writecb, errorcb errcb, void * arg)
25 _readcb = readcb;
26 _writecb = writecb;
27 _errorcb = errcb;
29 _arg = arg;
32 // Future: to be deprecated by EvBufferEvent(...) throw(...)
33 /* public: for now */
34 /**
35 * Open the bufferevent object with the file/socket descriptor
37 void open(int fd) /* throw(...) */
39 (void)_bufferevent_new(fd);
42 /**
43 * Open the bufferevent object by accepting a connection on the socket descriptor
45 void accept(int listen_sock) /* throw(...) */
47 (void)_bufev_socket_accept(listen_sock);
50 /* public: */
52 /**
53 * Write data to the buffer.
55 * @param buf Buffer of data to be written.
57 * @param len Length of data to be written.
60 int write(const void * buf, int len)
62 return _write((char *)buf, len);
65 /**
66 * Read data from the buffer.
68 * @param buf Buffer to store data.
70 * @param len Size of buffer to store data.
73 int read(char * buf, int len)
75 return _read(buf, len);
78 /* protected: */
79 /* virtual */
80 void _readcb_handler()
82 (*_readcb)(_bufferevent, _arg);
85 /* virtual */
86 void _writecb_handler()
88 (*_writecb)(_bufferevent, _arg);
91 /* virtual */
92 void _errorcb_handler(short what)
94 (*_errorcb)(_bufferevent, what, _arg);
97 protected:
98 EvBufferEvent() { }
100 /* private: */
101 readwritecb _readcb, _writecb;
102 errorcb _errorcb;
103 void * _arg;
106 #endif // _EV_BUFFER_EVENT__HPP_
108 // vim: set filetype=cpp :