409 Commits

Author SHA1 Message Date
Nick Mathewson
215e629cd4 Add bufferevent_lock()/bufferevent_unlock()
Although bufferevent operations are threadsafe, sometimes you need
to make sure that a few operations on a single bufferevent will all
be executed with nothing intervening.  That's what these functions
are for.
2010-06-21 12:26:21 -04:00
Nick Mathewson
7b259b6796 Fix sentence fragment in docs for event_get_struct_event_size() 2010-06-21 12:24:49 -04:00
Nick Mathewson
e21f5d15eb Document a change in the semantics of event_get_struct_event_size() 2010-06-19 18:21:40 -04:00
Nick Mathewson
276e7ee97e Fix a pedantic gcc 4.4 warning in event2/event.h 2010-06-11 11:57:13 -04:00
Nick Mathewson
17a8e2d72b Add a function to retrieve the other side of a bufferevent pair 2010-06-07 12:06:43 -04:00
Felix Nawothnig
06bd05634d Fix the default HTTP error template
The current template...

<HTML><HEAD><TITLE>%s</TITLE>
</HEAD><BODY>
<H1>Method Not Implemented</H1>
Invalid method in request<P>
</BODY></HTML>

is highly confusing. The given title is easily overlooked and the
hard-coded content is just plain wrong in most cases (I really read
this as "the server did not understand the requested HTTP method)

This patch changes the template to include the error reason in the
body as well as in the header, and to infer the proper reason from
the status code whenever the reason argument is NULL.

This patch also removes a redundant evhttp_add_header from
evhttp_send_error; evhttp_send_page already adds a "Connection:
close" header.
2010-05-26 13:43:01 -04:00
Nick Mathewson
fdfc3fc502 Remove the now-unusable EVTHREAD_LOCK/UNLOCK constants 2010-05-13 15:40:43 -04:00
Nick Mathewson
7c519dfd4f Fix some autoconf issues on OpenBSD
Issue 1: autoconf gets accept when a header works properly with cpp
but not with cc.  This was true of the sys/sysctl.h header on
openbsd.  The fix: include sys/param.h (if present) when testing for
sys/sysctl.h

Issue 2: Somehow, autoconf's macro generation code is messed up on
some versions of openbsd (including mine, and other people's too) so
that instead of SIZEOF_VOID_P, it makes SIZEOF_VOID__.
evutil/util.h now works around that.
2010-05-08 23:31:35 -04:00
Nick Mathewson
a62c843340 Merge commit 'chrisd/connect-hostname-report-err' 2010-05-06 14:16:50 -04:00
Nick Mathewson
c16e68448c Rename current_base symbol to event_global_current_base_
The "current_base" symbol was never actually declared in an exported
header; it's hideously deprecated, and it was the one remaining
exported symbol (fwict) that was prefixed with neither ev nor
bufferevent nor _ev nor _bufferevent.

codesearch.google.com turns up no actual attempts to use our
current_base from outside libevent.
2010-05-04 13:27:36 -04:00
Joachim Bauch
a5208fe422 Release locks on bufferevents while executing callbacks
This fixes a dead lock for me where bufferevents in different event
loops use each other and access their input/output buffers (proxy-like
scenario).
2010-04-27 14:24:38 -04:00
Christopher Davis
0ef407065e Report DNS error when lookup fails during bufferevent_socket_connect_hostname. 2010-04-24 00:06:38 -07:00
Nick Mathewson
a5bf43abb0 Document evutil_secure_rng_init() and evutil_secure_rng_add_bytes() 2010-04-23 15:46:09 -04:00
Sebastian Sjöberg
899c1dcc98 Replace EVUTIL_CLOSESOCKET macro with a function
The EVUTIL_CLOSESOCKET() macro required you to include unistd.h in your
source for POSIX.  We might as well turn it into a function: an extra
function call is going to be cheap in comparison with the system call.

We retain the EVUTIL_CLOSESOCKET() macro as an alias for the new
evutil_closesocket() function.

(commit message from email by Nick and Sebastian)
2010-04-14 15:42:57 -04:00
Shuo Chen
755fbf16c3 Add void* arguments to request_new and reply_new evrpc hooks
This makes evprc setup more extensible, and helps with Shuo Chen's
work on implementing Google protocol buffers rpc on top of Libevent 2
evrpc.

This patch breaks binary compatibility with previous versions of
Libevent, since it changes struct evrpc and the signature of
evrpc_register_generic().  Since all compliant code should be calling
evrpc_register_generic via EVRPC_REGISTER, it shouldn't break source
compatibility.

(Code by Shuo Chen; commit message by Nick)
2010-04-14 14:27:29 -04:00
Shuo Chen
07edf784fa Expose the request and reply members of rpc_req_generic()
This code adds two accessor functions to evprc, and helps integrate
evrpc with Google protocol buffers.

(Code by Shuo Chen; commit message by nickm)
2010-04-14 14:23:03 -04:00
Nick Mathewson
eb86c8c5ff Add evbuffer_copyout to copy data from an evbuffer without draining
The evbuffer_remove() function copies data from the front of an
evbuffer into an array of char, and removes the data from the buffer.
This function behaves the same, but does not remove the data.  This
behavior can be handy for lots of protocols, where you want the
evbuffer to accumulate data until a complete record has arrived.

Lots of people have asked for a function more or less like this, and
though it isn't too hard to code one from evbuffer_peek(), it is
apparently annoying to do it in every app you write.  The
evbuffer_peek() function is significantly faster, but it requires that
the user be able to handle data in separate extents.

This patch also reimplements evbufer_remove() as evbuffer_copyout()
followed by evbuffer_drain().  I am reasonably confident that this
won't be a performance hit: the memcpy() overhead should dominate the
cost of walking the list an extra time.
2010-04-13 01:42:01 -04:00
Nick Mathewson
6494772e32 Use LIST rather than TAILQ for evmap_io and evmap_signal
These structures used TAILQ for the lists of events waiting on a
single fd or signal.  But order doesn't matter for these lists; only
the order of the active events lists actually matters.
2010-04-09 19:54:21 -04:00
Nick Mathewson
f9db33d15d Add LIST_ delaration to event_struct.h to supplment TAILQ_
Generally, LIST_ can be a little faster than TAILQ_ for most
operations.  We only need to use TAILQ_ when we care about traversing
lists from tail-to-head, or we need to be able to add items to the end
of the list.
2010-04-09 19:43:54 -04:00
Nick Mathewson
fb366c1d88 Functions to track the total bytes sent over a rate limit group. 2010-03-21 13:16:31 -04:00
Nick Mathewson
ee41aca63e Functions to manipulate existing rate limiting groups.
This patch adds a function to change the current rate limit of a rate
limiting group, and another to free an empty rate limiting group.
2010-03-12 00:47:39 -05:00
Nick Mathewson
b2f2be6edc Make evdns use the regular logging system by default
Once, for reasons that made sense at the time, we had evdns.c use its
own logging subsystem with two levels, "warn" and "debug".  This leads
to problems, since setting a log handler for Libevent wouldn't actually
trap these messages, since they weren't on by default, and since some of
the warns should really be msgs.

This patch changes the default behavior of evdns.c to log to
event_(debugx,warnx,msgx) by default, and adds a new (internal-use-only)
log level of EVDNS_LOG_MSG.  Programs that set a evdns logging
function will see no change.  Programs that don't will now see evdns
warnings reported like other warnings.
2010-03-10 16:25:16 -05:00
Nick Mathewson
17efc1cdfa Update all our copyright notices to say "2010" 2010-03-04 01:38:48 -05:00
Nick Mathewson
2fac0f70a3 Remove signal_assign() and signal_new() macros.
These were introduced and deprecated in the same version (2.0.1-alpha),
presumably in two-stage process.  Everybody sane should be using
evsignal_assign() and evsignal_new() instead.
2010-03-03 12:15:15 -05:00
Nick Mathewson
d3288293fd Provide consistent, tested semantics for bufferevent timeouts
The different bufferevent implementations had different behavior for
their timeouts.  Some of them kept re-triggering the timeouts
indefinitely; some disabled the event immediately the first time a
timeout triggered.  Some of them made the timeouts only count when
the bufferevent was actively trying to read or write; some did not.

The new behavior is modeled after old socket bufferevents, since
they were here first and their behavior is relatively sane.
Basically, each timeout disables the bufferevent's corresponding
read or write operation when it fires.  Timeouts are stopped
whenever we suspend writing or reading, and reset whenever we
unsuspend writing or reading.  Calling bufferevent_enable resets a
timeout, as does changing the timeout value.
2010-02-23 15:20:33 -05:00
Nick Mathewson
162ce8a856 Expose view of current rate limit as constrained by group limit 2010-02-23 00:38:30 -05:00
Nick Mathewson
4faeaea90e Clean up formatting: function/keyword spacing consistency.
- Keywords always have a space before a paren.  Functions never do.

- No more than 3 blank lines in a row.
2010-02-19 03:39:50 -05:00
Nick Mathewson
e5cf98795e Clean up formatting: remove trailing spaces 2010-02-18 17:46:56 -05:00
Nick Mathewson
e5bbd40ad7 Clean up formatting: use tabs, not 8-spaces, to indent. 2010-02-18 17:44:09 -05:00
Nick Mathewson
8fdf09c09d Clean up formatting: Disallow space-before-tab. 2010-02-18 17:08:50 -05:00
Nick Mathewson
ca46d25b01 Merge branch 'arc4random' 2010-02-17 23:02:28 -05:00
Nick Mathewson
3fe60fdf47 Use off_t for the length parameter of evbuffer_add_file 2010-02-12 23:40:13 -05:00
Nick Mathewson
d4de062efc Add an arc4random implementation for use by evdns
Previously, evdns was at the mercy of the user for providing a good
entropy source; without one, it would be vulnerable to various
active attacks.

This patch adds a port of OpenBSD's arc4random() calls to Libevent
[port by Chris Davis], and wraps it up a little bit so we can use it
more safely.
2010-02-11 12:53:32 -05:00
Nick Mathewson
1dd7e6dc3a Remove the 'flags' argument from evdns_base_set_option()
The 'flags' argument made sense when passed to
evdns_(base_)?parse_resolv_conf when it said which parts of the
resolv.conf file to obey.  But for evdns_set_option(), it was really
silly, since you wouldn't be calling evdns_set_option() unless you
actually wanted to set the option.  Its meaning was basically, "set
this to DNS_OPTIONS_ALL unless you want a funny surprise."

evdns_base_set_option was new in 2.0.1-alpha, so we aren't committed
to keeping it source-compatible.
2010-02-05 13:55:12 -05:00
Nick Mathewson
cfe7a9ff4c Merge remote branch 'niels/http_chunk' 2010-02-04 10:15:39 -05:00
Niels Provos
397818011b make evhttp_send() safe against terminated connections, too 2010-02-03 16:54:18 -08:00
Nick Mathewson
e2d15d81c3 Merge remote branch 'niels/http_chunk' 2010-02-03 17:52:55 -05:00
Niels Provos
93d7369106 do not fail while sending on http connections the client closed.
when sending chunked requests via multiple calls to evhttp_send_reply_chunk,
the client may close the connection before the server is done sending. this
used to cause a crash.

we introduce a new function evhttp_request_get_connection() that allows the
server to determine if the request is still associated with a connection.
If it's not, evhttp_request_free() needs to be called explicitly or the user
can call evhttp_send_reply_end() which just frees the request, too.
2010-02-03 14:34:56 -08:00
Nick Mathewson
60742d581b Add the rest of the integer limits, and add a test for them. 2010-02-03 17:01:45 -05:00
Nick Mathewson
85047a6983 Functions to view and manipulate rate-limiting buckets.
We need these for Tor, and other projects probably need them too.  Uses
include:
    - Checking whether bandwidth is mostly-used, and only taking some
      actions when there's plenty of bandwidth.
    - Deducting some non-bufferevent activities from a rate-limit group.
2010-02-03 15:12:04 -05:00
Nick Mathewson
aba1fff33a Add EV_*_MAX macros to event2/util.h to expose limits for ev_* types. 2010-02-03 14:37:42 -05:00
Nick Mathewson
da6135e356 Reduce windows header includes in our own headers.
It turns out that absolutely everything that was including
windows.h was doing so needlessly; our headers don't need it,
so we should just include winsock2.h (since that's where
struct timeval is defined).

Pre-2.0 code will use the old headers, which include windows.h
for them, so we aren't breaking source compatibility with 1.4.

This solves the bug where we were leaving WIN32_LEAN_AND_MEAN
defined, in roughly the same way that buying an automobile
solves the question of what to give your coachman for boxing
day.
2010-02-03 02:09:19 -05:00
Nick Mathewson
27c9a40f15 Fix a dumb typo in ev_intptr_t definitions.
We said "#define ev_uintptr_t" twice instead of ever saying
"#define ev_intptr_t".
2010-02-03 02:08:08 -05:00
Nick Mathewson
6c21c895d9 Remove EVUTIL_CHECK_FMT.
This was never supposed to be an exposed API, so its name should have been
more like _EVUTIL_CHECK_FMT.  But it was only used in one place, so let's
just eliminate it.
2010-02-03 01:22:44 -05:00
Nick Mathewson
f6b269498a Deprecate EVENT_FD and EVENT_SIGNAL.
These are old aliases for event_get_fd and event_get_signal, and they
haven't been the preferred way of doing things since 2.0.1-alpha.

For a while, we made them use struct event if it was included, but call
event_get_(fd|signal) if it wasn't.  This was entirely too cute.
2010-02-03 01:16:47 -05:00
Nick Mathewson
d38a7a1931 const-ify a few more functions in event.h 2010-02-02 15:44:10 -05:00
Nick Mathewson
1fa4c81c71 Add ev_[u]intptr_t to include/event2/util.h
We already emulate most of the other useful bits of stdint.h, and
we seem to have started to use uintptr_t in a few places throughout
the code.  Let's make sure we can continue to do so even on backwards
platforms that don't do C99.
2010-01-26 12:06:41 -05:00
Nick Mathewson
361da8f202 Note a missing ratelim function 2010-01-25 13:54:14 -05:00
Nick Mathewson
cd17c3acd5 Add support for a "debug mode" to try to catch common errors.
Right now it only catches cases where we aren't initializing events,
or where we are re-initializing events without deleting them first.
These are however shockingly common.
2010-01-25 13:53:13 -05:00
Nick Mathewson
70a4a3ef14 Remove a needless include of rpc_compat.h
Nothing in evrpc.c was using rpc_compat.h, so it's best to take it
out, especially since it polluted our build process with GCC variadic
macros.

While we're at it, this patch puts an extra restriction on when the
variadic macros in rpc_compat.h are defined.  Not only must GCC be the
compiler, but GCC must not be running in -ansi mode.
2010-01-23 23:12:29 -05:00