1 #ifndef _EV_BUFFER_EVENT_INTERNAL__HPP_
2 #define _EV_BUFFER_EVENT_INTERNAL__HPP_
7 struct EvBufferEventInternal
12 * Constructor to setup callbacks
14 EvBufferEventInternal()
21 * Open the bufferevent object with the file/socket descriptor
22 * by calling ::bufferevent_new()
24 struct bufferevent
* _bufferevent_new(int fd
) /* throw(...) */
27 ::bufferevent_new(fd
, _readcb_wrapper
, _writecb_wrapper
, _errorcb_wrapper
,
28 reinterpret_cast< void * >(this));
32 * Open the bufferevent object with the listen socket descriptor
33 * by calling ::bufev_socket_accept()
35 struct bufferevent
* _bufev_socket_accept(int listen_sock
) /* throw(...) */
38 ::bufev_socket_accept(listen_sock
, _readcb_wrapper
, _writecb_wrapper
, _errorcb_wrapper
,
39 reinterpret_cast< void * >(this));
42 /* TODO (future): protected: */
44 * Enable certain bufferevent callbacks by calling ::bufferevent_enable()
48 return ::bufferevent_enable(_bufferevent
, ev
);
52 * Disable certain bufferevent callbacks by calling ::bufferevent_disable()
54 int _disable(short ev
)
56 return ::bufferevent_disable(_bufferevent
, ev
);
59 int _write(char * buf
, int len
)
61 return ::bufferevent_write(_bufferevent
, buf
, len
);
64 int _read(char * buf
, int len
)
66 return ::bufferevent_read(_bufferevent
, buf
, len
);
71 return EVBUFFER_LENGTH(_bufferevent
->input
);
75 return EVBUFFER_LENGTH(_bufferevent
->output
);
79 virtual ~EvBufferEventInternal()
81 if (_bufferevent
!= NULL
)
82 ::bufferevent_free(_bufferevent
);
86 struct bufferevent
* _bufferevent
;
88 /* TODO (future): protected: */
89 virtual void _readcb_handler()
90 { /* to be overridden by derived bufferevent class */ }
92 virtual void _writecb_handler()
93 { /* to be overridden by derived bufferevent class */ }
95 virtual void _errorcb_handler(short)
96 { /* to be overridden by derived bufferevent class */ }
98 /* TODO (future): private: */
99 static void _readcb_wrapper(bufferevent
*, void * arg
)
101 EvBufferEventInternal
* bufferevent_self
= reinterpret_cast< EvBufferEventInternal
* >(arg
);
103 bufferevent_self
->_readcb_handler();
106 static void _writecb_wrapper(bufferevent
*, void * arg
)
108 EvBufferEventInternal
* bufferevent_self
= reinterpret_cast< EvBufferEventInternal
* >(arg
);
110 bufferevent_self
->_writecb_handler();
113 static void _errorcb_wrapper(bufferevent
*, short what
, void * arg
)
115 EvBufferEventInternal
* bufferevent_self
= reinterpret_cast< EvBufferEventInternal
* >(arg
);
117 bufferevent_self
->_errorcb_handler(what
);
122 #endif // _EV_BUFFER_EVENT_INTERNAL__HPP_
124 // vim: set filetype=cpp :