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 #ifndef _EVENT2_BUFFER_H_
00027 #define _EVENT2_BUFFER_H_
00028
00064 #ifdef __cplusplus
00065 extern "C" {
00066 #endif
00067
00068 #include <event-config.h>
00069 #include <stdarg.h>
00070 #ifdef _EVENT_HAVE_SYS_TYPES_H
00071 #include <sys/types.h>
00072 #endif
00073 #include <event2/util.h>
00074
00075 struct evbuffer;
00076
00082 struct evbuffer_ptr {
00083 ssize_t pos;
00084
00085
00086 struct {
00087 void *chain;
00088 size_t pos_in_chain;
00089 } _internal;
00090 };
00091
00098 struct evbuffer *evbuffer_new(void);
00099
00100
00106 void evbuffer_free(struct evbuffer *buf);
00107
00120 int evbuffer_enable_locking(struct evbuffer *buf, void *lock);
00121
00126 void evbuffer_lock(struct evbuffer *buf);
00127
00132 void evbuffer_unlock(struct evbuffer *buf);
00133
00140 size_t evbuffer_get_length(const struct evbuffer *buf);
00141
00154 size_t evbuffer_get_contiguous_space(const struct evbuffer *buf);
00155
00166 int evbuffer_expand(struct evbuffer *buf, size_t datlen);
00167
00185 unsigned char *evbuffer_reserve_space(struct evbuffer *buf, size_t size);
00186
00199 int evbuffer_commit_space(struct evbuffer *buf, size_t size);
00200
00201
00210 int evbuffer_add(struct evbuffer *buf, const void *data, size_t datlen);
00211
00212
00221 int evbuffer_remove(struct evbuffer *buf, void *data, size_t datlen);
00222
00233 int evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
00234 size_t datlen);
00235
00238 enum evbuffer_eol_style {
00240 EVBUFFER_EOL_ANY,
00243 EVBUFFER_EOL_CRLF,
00245 EVBUFFER_EOL_CRLF_STRICT,
00247 EVBUFFER_EOL_LF
00248 };
00249
00264 char *evbuffer_readln(struct evbuffer *buffer, size_t *n_read_out,
00265 enum evbuffer_eol_style eol_style);
00266
00277 int evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf);
00278
00294 int evbuffer_add_reference(struct evbuffer *outbuf,
00295 const void *data, size_t datlen,
00296 void (*cleanupfn)(void *extra), void *extra);
00297
00317 int evbuffer_add_file(struct evbuffer *output, int fd, off_t offset,
00318 size_t length);
00319
00329 int evbuffer_add_printf(struct evbuffer *buf, const char *fmt, ...)
00330 #ifdef __GNUC__
00331 __attribute__((format(printf, 2, 3)))
00332 #endif
00333 ;
00334
00335
00344 int evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap);
00345
00346
00354 int evbuffer_drain(struct evbuffer *buf, size_t len);
00355
00356
00367 int evbuffer_write(struct evbuffer *buffer, evutil_socket_t fd);
00368
00381 int evbuffer_write_atmost(struct evbuffer *buffer, evutil_socket_t fd,
00382 ssize_t howmuch);
00383
00393 int evbuffer_read(struct evbuffer *buffer, evutil_socket_t fd, int howmuch);
00394
00406 struct evbuffer_ptr evbuffer_search(struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start);
00407
00408 enum evbuffer_ptr_how {
00411 EVBUFFER_PTR_SET,
00413 EVBUFFER_PTR_ADD
00414 };
00415
00428 int
00429 evbuffer_ptr_set(struct evbuffer *buffer, struct evbuffer_ptr *pos,
00430 size_t position, enum evbuffer_ptr_how how);
00431
00433 struct evbuffer_cb_info {
00435 size_t orig_size;
00436 size_t n_added;
00437 size_t n_deleted;
00438 };
00439
00459 typedef void (*evbuffer_cb_func)(struct evbuffer *buffer, const struct evbuffer_cb_info *info, void *arg);
00460
00461 struct evbuffer_cb_entry;
00473 struct evbuffer_cb_entry *evbuffer_add_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg);
00474
00483 int evbuffer_remove_cb_entry(struct evbuffer *buffer,
00484 struct evbuffer_cb_entry *ent);
00485
00492 int evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg);
00493
00494 #define EVBUFFER_CB_DISABLED 0
00495 #define EVBUFFER_CB_ENABLED 1
00496
00506 int evbuffer_cb_set_flags(struct evbuffer *buffer,
00507 struct evbuffer_cb_entry *cb, ev_uint32_t flags);
00508
00509 #if 0
00510
00519 void evbuffer_cb_suspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb);
00528 void evbuffer_cb_unsuspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb);
00529 #endif
00530
00540 unsigned char *evbuffer_pullup(struct evbuffer *buf, ssize_t size);
00541
00551 int evbuffer_prepend(struct evbuffer *buf, const void *data, size_t size);
00552
00561 int evbuffer_prepend_buffer(struct evbuffer *dst, struct evbuffer* src);
00562
00577 int evbuffer_freeze(struct evbuffer *buf, int at_front);
00586 int evbuffer_unfreeze(struct evbuffer *buf, int at_front);
00587
00588 struct event_base;
00596 int evbuffer_defer_callbacks(struct evbuffer *buffer, struct event_base *base);
00597
00598 #ifdef __cplusplus
00599 }
00600 #endif
00601
00602 #endif