o Use AC_SEARCH_LIBS, not AC_CHECK_LIB to avoid needless library use.
o Do not allow event_del(ev) to return while that event's callback is executing in another thread. This fixes a nasty race condition.
o event_get_supported_methods() now lists methods that have been disabled with the EVENT_NO* environment options.
+ o Rename encode_int[64] to evtag_encode_int[64] to avoid polluting the global namespace. The old method names are still available as macros in event2/tag_compat.h.
Changes in 2.0.1-alpha:
o free minheap on event_base_free(); from Christopher Layne
#include <event2/bufferevent_struct.h>
#include <event2/bufferevent_compat.h>
#include <event2/tag.h>
+#include <event2/tag_compat.h>
#ifdef __cplusplus
}
#include "util-internal.h"
int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf);
+int evtag_decode_int64(ev_uint64_t *pnumber, struct evbuffer *evbuf);
int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t tag);
int evtag_decode_tag(ev_uint32_t *ptag, struct evbuffer *evbuf);
}
void
-encode_int(struct evbuffer *evbuf, ev_uint32_t number)
+evtag_encode_int(struct evbuffer *evbuf, ev_uint32_t number)
{
ev_uint8_t data[5];
int len = encode_int_internal(data, number);
}
void
-encode_int64(struct evbuffer *evbuf, ev_uint64_t number)
+evtag_encode_int64(struct evbuffer *evbuf, ev_uint64_t number)
{
ev_uint8_t data[9];
int len = encode_int64_internal(data, number);
const void *data, ev_uint32_t len)
{
evtag_encode_tag(evbuf, tag);
- encode_int(evbuf, len);
+ evtag_encode_int(evbuf, len);
evbuffer_add(evbuf, (void *)data, len);
}
struct evbuffer *data)
{
evtag_encode_tag(evbuf, tag);
- encode_int(evbuf, evbuffer_get_length(data));
+ evtag_encode_int(evbuf, evbuffer_get_length(data));
evbuffer_add_buffer(evbuf, data);
}
int len = encode_int_internal(data, integer);
evtag_encode_tag(evbuf, tag);
- encode_int(evbuf, len);
+ evtag_encode_int(evbuf, len);
evbuffer_add(evbuf, data, len);
}
int len = encode_int64_internal(data, integer);
evtag_encode_tag(evbuf, tag);
- encode_int(evbuf, len);
+ evtag_encode_int(evbuf, len);
evbuffer_add(evbuf, data, len);
}
return (res == -1 ? -1 : 0);
}
+int
+evtag_decode_int64(ev_uint64_t *pnumber, struct evbuffer *evbuf)
+{
+ int res = decode_int64_internal(pnumber, evbuf, 0);
+ if (res != -1)
+ evbuffer_drain(evbuf, res);
+
+ return (res == -1 ? -1 : 0);
+}
+
int
evtag_peek(struct evbuffer *evbuf, ev_uint32_t *ptag)
{
EXTRA_SRC = event2/buffer.h event2/buffer_compat.h \
event2/thread.h event2/bufferevent.h event2/bufferevent_compat.h \
event2/bufferevent_struct.h event2/event.h event2/event_compat.h \
- event2/event_struct.h event2/tag.h event2/util.h \
+ event2/event_struct.h event2/tag.h event2/tag_compat.h event2/util.h \
event2/http.h event2/http_struct.h event2/http_compat.h \
event2/listener.h
event2/thread.h event2/bufferevent.h \
event2/bufferevent_compat.h \
event2/bufferevent_struct.h event2/event.h event2/event_compat.h \
- event2/event_struct.h event2/tag.h event2/util.h \
+ event2/event_struct.h event2/tag.h event2/tag_compat.h event2/util.h \
event2/http.h event2/http_struct.h event2/http_compat.h \
event2/rpc.h event2/rpc_struct.h event2/rpc_compat.h \
event2/dns.h event2/dns_struct.h event2/dns_compat.h \
@param evbuf evbuffer to store the encoded number
@param number a 32-bit integer
*/
-void encode_int(struct evbuffer *evbuf, ev_uint32_t number);
-void encode_int64(struct evbuffer *evbuf, ev_uint64_t number);
+void evtag_encode_int(struct evbuffer *evbuf, ev_uint32_t number);
+void evtag_encode_int64(struct evbuffer *evbuf, ev_uint64_t number);
void evtag_marshal_int(struct evbuffer *evbuf, ev_uint32_t tag,
ev_uint32_t integer);
--- /dev/null
+/*
+ * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
+ * Copyright (c) 2007-2009 Niels Provos and Nick Mathewson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _EVENT2_TAG_COMPAT_H_
+#define _EVENT2_TAG_COMPAT_H_
+
+/** @file tag_compat.h
+
+ Obsolete/deprecated functions from tag.h; provided only for backwards
+ compatibility.
+ */
+
+#define encode_int(evbuf, number) evtag_encode_int((evbuf), (number))
+#define encode_int64(evbuf, number) evtag_encode_int64((evbuf), (number))
+
+#endif /* _EVENT2_TAG_H_ */
}
int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf);
+int evtag_decode_int64(ev_uint64_t *pnumber, struct evbuffer *evbuf);
int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t number);
int evtag_decode_tag(ev_uint32_t *pnumber, struct evbuffer *evbuf);
0xaf0, 0x1000, 0x1, 0xdeadbeef, 0x00, 0xbef000
};
ev_uint32_t integer;
+ ev_uint64_t big_int;
int i;
for (i = 0; i < TEST_MAX_INT; i++) {
int oldlen, newlen;
oldlen = EVBUFFER_LENGTH(tmp);
- encode_int(tmp, integers[i]);
- newlen = EVBUFFER_LENGTH(tmp);
- TT_BLATHER(("encoded 0x%08x with %d bytes",
+ evtag_encode_int(tmp, integers[i]);
+ newlen = EVBUFFER_LENGTH(tmp);
+ TT_BLATHER(("encoded 0x%08x with %d bytes",
(unsigned)integers[i], newlen - oldlen));
+ big_int = integers[i];
+ big_int *= 1000000000; /* 1 billion */
+ evtag_encode_int64(tmp, big_int);
}
for (i = 0; i < TEST_MAX_INT; i++) {
- tt_assert(evtag_decode_int(&integer, tmp) != -1);
+ tt_int_op(evtag_decode_int(&integer, tmp), !=, -1);
tt_uint_op(integer, ==, integers[i]);
+ tt_int_op(evtag_decode_int64(&big_int, tmp), !=, -1);
+ tt_assert((big_int / 1000000000) == integers[i]);
}
tt_uint_op(EVBUFFER_LENGTH(tmp), ==, 0);
+
end:
evbuffer_free(tmp);
}