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 <event2/event-config.h>
00069 #include <stdarg.h>
00070 #ifdef _EVENT_HAVE_SYS_TYPES_H
00071 #include <sys/types.h>
00072 #endif
00073 #ifdef _EVENT_HAVE_SYS_UIO_H
00074 #include <sys/uio.h>
00075 #endif
00076 #include <event2/util.h>
00077
00078 struct evbuffer;
00079
00085 struct evbuffer_ptr {
00086 ev_ssize_t pos;
00087
00088
00089 struct {
00090 void *chain;
00091 size_t pos_in_chain;
00092 } _internal;
00093 };
00094
00100 #ifdef _EVENT_HAVE_SYS_UIO_H
00101 #define evbuffer_iovec iovec
00102
00103 #define _EVBUFFER_IOVEC_IS_NATIVE
00104 #else
00105 struct evbuffer_iovec {
00107 void *iov_base;
00109 size_t iov_len;
00110 };
00111 #endif
00112
00119 struct evbuffer *evbuffer_new(void);
00120
00121
00127 void evbuffer_free(struct evbuffer *buf);
00128
00141 int evbuffer_enable_locking(struct evbuffer *buf, void *lock);
00142
00147 void evbuffer_lock(struct evbuffer *buf);
00148
00153 void evbuffer_unlock(struct evbuffer *buf);
00154
00161 size_t evbuffer_get_length(const struct evbuffer *buf);
00162
00175 size_t evbuffer_get_contiguous_space(const struct evbuffer *buf);
00176
00187 int evbuffer_expand(struct evbuffer *buf, size_t datlen);
00188
00221 int
00222 evbuffer_reserve_space(struct evbuffer *buf, ev_ssize_t size,
00223 struct evbuffer_iovec *vec, int n_vecs);
00224
00246 int evbuffer_commit_space(struct evbuffer *buf,
00247 struct evbuffer_iovec *vec, int n_vecs);
00248
00257 int evbuffer_add(struct evbuffer *buf, const void *data, size_t datlen);
00258
00259
00268 int evbuffer_remove(struct evbuffer *buf, void *data, size_t datlen);
00269
00278 ev_ssize_t evbuffer_copyout(struct evbuffer *buf, void *data_out, size_t datlen);
00279
00290 int evbuffer_remove_buffer(struct evbuffer *src, struct evbuffer *dst,
00291 size_t datlen);
00292
00295 enum evbuffer_eol_style {
00297 EVBUFFER_EOL_ANY,
00300 EVBUFFER_EOL_CRLF,
00302 EVBUFFER_EOL_CRLF_STRICT,
00304 EVBUFFER_EOL_LF
00305 };
00306
00321 char *evbuffer_readln(struct evbuffer *buffer, size_t *n_read_out,
00322 enum evbuffer_eol_style eol_style);
00323
00334 int evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf);
00335
00336
00337 typedef void (*evbuffer_ref_cleanup_cb)(const void *data,
00338 size_t datalen, void *extra);
00339
00355 int evbuffer_add_reference(struct evbuffer *outbuf,
00356 const void *data, size_t datlen,
00357 evbuffer_ref_cleanup_cb cleanupfn, void *extra);
00358
00378 int evbuffer_add_file(struct evbuffer *output, int fd, ev_off_t offset,
00379 ev_off_t length);
00380
00390 int evbuffer_add_printf(struct evbuffer *buf, const char *fmt, ...)
00391 #ifdef __GNUC__
00392 __attribute__((format(printf, 2, 3)))
00393 #endif
00394 ;
00395
00396
00405 int evbuffer_add_vprintf(struct evbuffer *buf, const char *fmt, va_list ap);
00406
00407
00415 int evbuffer_drain(struct evbuffer *buf, size_t len);
00416
00417
00428 int evbuffer_write(struct evbuffer *buffer, evutil_socket_t fd);
00429
00442 int evbuffer_write_atmost(struct evbuffer *buffer, evutil_socket_t fd,
00443 ev_ssize_t howmuch);
00444
00454 int evbuffer_read(struct evbuffer *buffer, evutil_socket_t fd, int howmuch);
00455
00467 struct evbuffer_ptr evbuffer_search(struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start);
00468
00483 struct evbuffer_ptr evbuffer_search_range(struct evbuffer *buffer, const char *what, size_t len, const struct evbuffer_ptr *start, const struct evbuffer_ptr *end);
00484
00485 enum evbuffer_ptr_how {
00488 EVBUFFER_PTR_SET,
00490 EVBUFFER_PTR_ADD
00491 };
00492
00505 int
00506 evbuffer_ptr_set(struct evbuffer *buffer, struct evbuffer_ptr *pos,
00507 size_t position, enum evbuffer_ptr_how how);
00508
00523 struct evbuffer_ptr evbuffer_search_eol(struct evbuffer *buffer,
00524 struct evbuffer_ptr *start, size_t *eol_len_out,
00525 enum evbuffer_eol_style eol_style);
00526
00528 struct evbuffer_cb_info {
00530 size_t orig_size;
00531 size_t n_added;
00532 size_t n_deleted;
00533 };
00534
00561 int evbuffer_peek(struct evbuffer *buffer, ev_ssize_t len,
00562 struct evbuffer_ptr *start_at,
00563 struct evbuffer_iovec *vec_out, int n_vec);
00564
00584 typedef void (*evbuffer_cb_func)(struct evbuffer *buffer, const struct evbuffer_cb_info *info, void *arg);
00585
00586 struct evbuffer_cb_entry;
00598 struct evbuffer_cb_entry *evbuffer_add_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg);
00599
00608 int evbuffer_remove_cb_entry(struct evbuffer *buffer,
00609 struct evbuffer_cb_entry *ent);
00610
00617 int evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg);
00618
00621 #define EVBUFFER_CB_ENABLED 1
00622
00630 int evbuffer_cb_set_flags(struct evbuffer *buffer,
00631 struct evbuffer_cb_entry *cb, ev_uint32_t flags);
00632
00640 int evbuffer_cb_clear_flags(struct evbuffer *buffer,
00641 struct evbuffer_cb_entry *cb, ev_uint32_t flags);
00642
00643 #if 0
00644
00653 void evbuffer_cb_suspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb);
00662 void evbuffer_cb_unsuspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb);
00663 #endif
00664
00674 unsigned char *evbuffer_pullup(struct evbuffer *buf, ev_ssize_t size);
00675
00685 int evbuffer_prepend(struct evbuffer *buf, const void *data, size_t size);
00686
00695 int evbuffer_prepend_buffer(struct evbuffer *dst, struct evbuffer* src);
00696
00711 int evbuffer_freeze(struct evbuffer *buf, int at_front);
00720 int evbuffer_unfreeze(struct evbuffer *buf, int at_front);
00721
00722 struct event_base;
00730 int evbuffer_defer_callbacks(struct evbuffer *buffer, struct event_base *base);
00731
00732 #ifdef __cplusplus
00733 }
00734 #endif
00735
00736 #endif