00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _EVENT2_BUFFEREVENT_H_
00028 #define _EVENT2_BUFFEREVENT_H_
00029
00053 #ifdef __cplusplus
00054 extern "C" {
00055 #endif
00056
00057 #include <event-config.h>
00058 #ifdef _EVENT_HAVE_SYS_TYPES_H
00059 #include <sys/types.h>
00060 #endif
00061 #ifdef _EVENT_HAVE_SYS_TIME_H
00062 #include <sys/time.h>
00063 #endif
00064
00065
00066 #include <event2/util.h>
00067
00068 #ifdef WIN32
00069 #define WIN32_LEAN_AND_MEAN
00070 #include <windows.h>
00071 #undef WIN32_LEAN_AND_MEAN
00072 #endif
00073
00074
00075
00076 #define EVBUFFER_READ 0x01
00077 #define EVBUFFER_WRITE 0x02
00078 #define EVBUFFER_EOF 0x10
00079 #define EVBUFFER_ERROR 0x20
00080 #define EVBUFFER_TIMEOUT 0x40
00081 struct bufferevent;
00082 struct event_base;
00083 struct evbuffer;
00084
00098
00099
00100 typedef void (*evbuffercb)(struct bufferevent *bev, void *ctx);
00101
00115
00116 typedef void (*everrorcb)(struct bufferevent *bev, short what, void *ctx);
00117
00119 enum bufferevent_options {
00122 BEV_OPT_CLOSE_ON_FREE = (1<<0),
00123
00126 BEV_OPT_THREADSAFE = (1<<1),
00127
00129 BEV_OPT_DEFER_CALLBACKS = (1<<2),
00130 };
00131
00142 struct bufferevent *bufferevent_socket_new(struct event_base *base, evutil_socket_t fd, enum bufferevent_options options);
00143
00152 int bufferevent_base_set(struct event_base *base, struct bufferevent *bufev);
00153
00154
00162 int bufferevent_priority_set(struct bufferevent *bufev, int pri);
00163
00164
00170 void bufferevent_free(struct bufferevent *bufev);
00171
00172
00187 void bufferevent_setcb(struct bufferevent *bufev,
00188 evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
00189
00196 void bufferevent_setfd(struct bufferevent *bufev, evutil_socket_t fd);
00197
00211 int bufferevent_write(struct bufferevent *bufev,
00212 const void *data, size_t size);
00213
00214
00224 int bufferevent_write_buffer(struct bufferevent *bufev, struct evbuffer *buf);
00225
00226
00237 size_t bufferevent_read(struct bufferevent *bufev, void *data, size_t size);
00238
00247 int bufferevent_read_buffer(struct bufferevent *bufev, struct evbuffer *buf);
00248
00258 struct evbuffer *bufferevent_get_input(struct bufferevent *bufev);
00259
00272 struct evbuffer *bufferevent_get_output(struct bufferevent *bufev);
00273
00282 int bufferevent_enable(struct bufferevent *bufev, short event);
00283
00292 int bufferevent_disable(struct bufferevent *bufev, short event);
00293
00294
00302 void bufferevent_set_timeouts(struct bufferevent *bufev,
00303 const struct timeval *timeout_read, const struct timeval *timeout_write);
00304
00323 void bufferevent_setwatermark(struct bufferevent *bufev, short events,
00324 size_t lowmark, size_t highmark);
00325
00327 #define EVBUFFER_INPUT(x) bufferevent_get_input(x)
00328
00329 #define EVBUFFER_OUTPUT(x) bufferevent_get_output(x)
00330
00335 enum bufferevent_flush_mode {
00337 BEV_NORMAL = 0,
00338
00340 BEV_FLUSH = 1,
00341
00343 BEV_FINISHED = 2,
00344 };
00345
00355 int bufferevent_flush(struct bufferevent *bufev,
00356 short iotype,
00357 enum bufferevent_flush_mode state);
00358
00366 enum bufferevent_filter_result {
00368 BEV_OK = 0,
00369
00371 BEV_NEED_MORE = 1,
00372
00375 BEV_ERROR = 2
00376 };
00377
00396 typedef enum bufferevent_filter_result (*bufferevent_filter_cb)(
00397 struct evbuffer *src, struct evbuffer *dst, ssize_t dst_limit,
00398 enum bufferevent_flush_mode mode, void *ctx);
00399
00413 struct bufferevent *
00414 bufferevent_filter_new(struct bufferevent *underlying,
00415 bufferevent_filter_cb input_filter,
00416 bufferevent_filter_cb output_filter,
00417 enum bufferevent_options options,
00418 void (*free_context)(void *),
00419 void *ctx);
00420
00431 int
00432 bufferevent_pair_new(struct event_base *base, enum bufferevent_options options,
00433 struct bufferevent *pair[2]);
00434
00435 #ifdef __cplusplus
00436 }
00437 #endif
00438
00439 #endif