1 | /* |
1 | /* |
2 | * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu> |
2 | * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu> |
|
|
3 | * Copyright (c) 2008 Marc Alexander Lehmann <libev@schmorp.de> |
3 | * All rights reserved. |
4 | * All rights reserved. |
4 | * |
5 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * are met: |
… | |
… | |
26 | */ |
27 | */ |
27 | #ifdef __cplusplus |
28 | #ifdef __cplusplus |
28 | extern "C" { |
29 | extern "C" { |
29 | #endif |
30 | #endif |
30 | |
31 | |
31 | #ifndef WIN32 |
|
|
32 | #include <sys/types.h> |
|
|
33 | #endif |
|
|
34 | #include <sys/time.h> |
|
|
35 | #include <inttypes.h> |
|
|
36 | #include <stdarg.h> |
|
|
37 | |
|
|
38 | #ifdef WIN32 |
32 | #ifdef _WIN32 |
39 | #define WIN32_LEAN_AND_MEAN |
33 | # define WIN32_LEAN_AND_MEAN |
40 | #include <windows.h> |
34 | # include <windows.h> |
41 | #undef WIN32_LEAN_AND_MEAN |
35 | # undef WIN32_LEAN_AND_MEAN |
42 | typedef unsigned char u_char; |
36 | typedef unsigned char u_char; |
43 | typedef unsigned short u_short; |
37 | typedef unsigned short u_short; |
|
|
38 | #else |
|
|
39 | # include <sys/types.h> |
|
|
40 | # include <sys/time.h> |
|
|
41 | # include <inttypes.h> |
44 | #endif |
42 | #endif |
|
|
43 | |
|
|
44 | #include <stdarg.h> |
45 | |
45 | |
46 | /* Fix so that ppl dont have to run with <sys/queue.h> */ |
46 | /* Fix so that ppl dont have to run with <sys/queue.h> */ |
47 | #ifndef TAILQ_ENTRY |
47 | #ifndef TAILQ_ENTRY |
48 | #define _EVENT_DEFINED_TQENTRY |
48 | #define _EVENT_DEFINED_TQENTRY |
49 | #define TAILQ_ENTRY(type) \ |
49 | #define TAILQ_ENTRY(type) \ |
… | |
… | |
152 | struct bufferevent *bufferevent_new(int fd, |
152 | struct bufferevent *bufferevent_new(int fd, |
153 | evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg); |
153 | evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg); |
154 | int bufferevent_base_set(struct event_base *base, struct bufferevent *bufev); |
154 | int bufferevent_base_set(struct event_base *base, struct bufferevent *bufev); |
155 | int bufferevent_priority_set(struct bufferevent *bufev, int pri); |
155 | int bufferevent_priority_set(struct bufferevent *bufev, int pri); |
156 | void bufferevent_free(struct bufferevent *bufev); |
156 | void bufferevent_free(struct bufferevent *bufev); |
157 | int bufferevent_write(struct bufferevent *bufev, void *data, size_t size); |
157 | int bufferevent_write(struct bufferevent *bufev, const void *data, size_t size); |
158 | int bufferevent_write_buffer(struct bufferevent *bufev, struct evbuffer *buf); |
158 | int bufferevent_write_buffer(struct bufferevent *bufev, struct evbuffer *buf); |
159 | size_t bufferevent_read(struct bufferevent *bufev, void *data, size_t size); |
159 | size_t bufferevent_read(struct bufferevent *bufev, void *data, size_t size); |
160 | int bufferevent_enable(struct bufferevent *bufev, short event); |
160 | int bufferevent_enable(struct bufferevent *bufev, short event); |
161 | int bufferevent_disable(struct bufferevent *bufev, short event); |
161 | int bufferevent_disable(struct bufferevent *bufev, short event); |
162 | void bufferevent_settimeout(struct bufferevent *bufev, |
162 | void bufferevent_settimeout(struct bufferevent *bufev, |
… | |
… | |
188 | * known ones - and we can just ignore the end of an event buffer. |
188 | * known ones - and we can just ignore the end of an event buffer. |
189 | */ |
189 | */ |
190 | |
190 | |
191 | void evtag_init(void); |
191 | void evtag_init(void); |
192 | |
192 | |
193 | void evtag_marshal(struct evbuffer *evbuf, uint8_t tag, const void *data, |
193 | void evtag_marshal(struct evbuffer *evbuf, uint32_t tag, const void *data, |
194 | uint32_t len); |
194 | uint32_t len); |
195 | |
195 | |
196 | void encode_int(struct evbuffer *evbuf, uint32_t number); |
196 | void encode_int(struct evbuffer *evbuf, uint32_t number); |
197 | |
197 | |
198 | void evtag_marshal_int(struct evbuffer *evbuf, uint8_t tag, uint32_t integer); |
198 | void evtag_marshal_int(struct evbuffer *evbuf, uint32_t tag, uint32_t integer); |
199 | |
199 | |
200 | void evtag_marshal_string(struct evbuffer *buf, uint8_t tag, |
200 | void evtag_marshal_string(struct evbuffer *buf, uint32_t tag, |
201 | const char *string); |
201 | const char *string); |
202 | |
202 | |
203 | void evtag_marshal_timeval(struct evbuffer *evbuf, uint8_t tag, |
203 | void evtag_marshal_timeval(struct evbuffer *evbuf, uint32_t tag, |
204 | struct timeval *tv); |
204 | struct timeval *tv); |
205 | |
205 | |
206 | void evtag_test(void); |
|
|
207 | |
|
|
208 | int evtag_unmarshal(struct evbuffer *src, uint8_t *ptag, struct evbuffer *dst); |
206 | int evtag_unmarshal(struct evbuffer *src, uint32_t *ptag, struct evbuffer *dst); |
209 | int evtag_peek(struct evbuffer *evbuf, uint8_t *ptag); |
207 | int evtag_peek(struct evbuffer *evbuf, uint32_t *ptag); |
210 | int evtag_peek_length(struct evbuffer *evbuf, uint32_t *plength); |
208 | int evtag_peek_length(struct evbuffer *evbuf, uint32_t *plength); |
211 | int evtag_payload_length(struct evbuffer *evbuf, uint32_t *plength); |
209 | int evtag_payload_length(struct evbuffer *evbuf, uint32_t *plength); |
212 | int evtag_consume(struct evbuffer *evbuf); |
210 | int evtag_consume(struct evbuffer *evbuf); |
213 | |
211 | |
214 | int evtag_unmarshal_int(struct evbuffer *evbuf, uint8_t need_tag, |
212 | int evtag_unmarshal_int(struct evbuffer *evbuf, uint32_t need_tag, |
215 | uint32_t *pinteger); |
213 | uint32_t *pinteger); |
216 | |
214 | |
217 | int evtag_unmarshal_fixed(struct evbuffer *src, uint8_t need_tag, void *data, |
215 | int evtag_unmarshal_fixed(struct evbuffer *src, uint32_t need_tag, void *data, |
218 | size_t len); |
216 | size_t len); |
219 | |
217 | |
220 | int evtag_unmarshal_string(struct evbuffer *evbuf, uint8_t need_tag, |
218 | int evtag_unmarshal_string(struct evbuffer *evbuf, uint32_t need_tag, |
221 | char **pstring); |
219 | char **pstring); |
222 | |
220 | |
223 | int evtag_unmarshal_timeval(struct evbuffer *evbuf, uint8_t need_tag, |
221 | int evtag_unmarshal_timeval(struct evbuffer *evbuf, uint32_t need_tag, |
224 | struct timeval *ptv); |
222 | struct timeval *ptv); |
225 | |
223 | |
226 | #ifdef __cplusplus |
224 | #ifdef __cplusplus |
227 | } |
225 | } |
228 | #endif |
226 | #endif |