63 Commits

Author SHA1 Message Date
Nick Mathewson
e49e289129 Update copyright notices to 2012 2012-02-10 17:29:53 -05:00
Greg Hewgill
d84d917099 Use C-style comments in C source files (for compatibility with compilers such as xlc on AIX). 2012-02-02 11:39:38 -05:00
Nick Mathewson
3c824bd334 Update copyright dates to 2011. 2011-10-24 13:18:09 -04:00
Nick Mathewson
0ba0af9c6c Prefer mmap to sendfile unless a DRAINS_TO_FD flag is set. Allows add_file to work with SSL.
The sendfile() implementation for evbuffer_add_file is potentially more
efficient, but it has a problem: you can only use it to send bytes over
a socket using sendfile().  If you are writing bytes via SSL_send() or
via a filter, or if you need to be able to inspect your buffer, it
doesn't work.

As an easy fix, this patch disables the sendfile-based implementation of
evbuffer_add_file on an evbuffer unless the user sets a new
EVBUFFER_FLAG_DRAINS_TO_FD flag on that evbuffer, indicating that the
evbuffer will not be inspected, but only written out via
evbuffer_write(), evbuffer_write_atmost(), or drained with stuff like
evbuffer_drain() or evbuffer_add_buffer().  This flag is off by
default, except for evbuffers used for output on bufferevent_socket.

In the future, it could be interesting to make a best-effort file
segment implementation that tries to send via sendfile, but mmaps on
demand.  That's too much complexity for a stable release series, though.
2011-09-29 10:32:16 -04:00
Nick Mathewson
e6af35d762 Correctly terminate IO on an async bufferevent on bufferevent_free 2011-08-28 14:39:12 -04:00
Harlan Stenn
7c11e51e1a Clean up some problems identified by Coverity. 2011-08-28 13:44:33 -04:00
Sebastian Hahn
65707d7c3c add some (void) casts for unused variables
All these places already have an XXX marker, so we know we need to fix
them later. Let's not clutter the static analysis results with them.
2011-04-23 02:04:58 +02:00
Nick Mathewson
7bcace2d54 Fix some irix compilation warnings spotted by Kevin Bowling 2010-11-22 21:02:34 -05:00
Nick Mathewson
7484df61c9 Fix even more win64 warnings 2010-11-01 13:43:43 -04:00
Nick Mathewson
598d133609 Try to clear up more size_t vs int/long issues. 2010-10-27 22:57:53 -04:00
Nick Mathewson
ec347b9225 Move event-config.h to include/event2
This change means that all required include files are in event2, and
all files not in event2/* are optional.
2010-08-06 20:21:27 -04:00
Christopher Davis
0ef407065e Report DNS error when lookup fails during bufferevent_socket_connect_hostname. 2010-04-24 00:06:38 -07: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
Nick Mathewson
657d1b6d3f Set mem_offset for every bufferevent type 2010-03-13 01:06:57 -05:00
Nick Mathewson
b34abf3069 Do not close(-1) when freeing an uninitialized socket bufferevent 2010-03-13 00:31:14 -05:00
Nick Mathewson
17efc1cdfa Update all our copyright notices to say "2010" 2010-03-04 01:38:48 -05:00
Nick Mathewson
57b7248823 Small cleanups on freebsd-connect-refused patch.
There should be no need to call be_socket_enable: that does an
event_add().  What we really want to do is event_active(), to make
sure that the writecb is executed.

Also, there was one "} if () {" that was missing an else.

I've noted that the return value for evutil_socket_connect() is
getting screwy, but since that isn't an exported function, we can fix
it whenever.
2010-02-27 22:27:13 -05:00
Niels Provos
7bc48bfd3a deal with connect() failing immediately 2010-02-27 18:59:06 -08: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
db08f640d5 Suspend read/write on bufferevents during hostname lookup
When we're doing a lookup in preparation for doing a connect, we
might have an unconnected socket on hand, and mustn't actually do
any reading or writing with it.
2010-02-20 12:55:59 -05:00
Nick Mathewson
8fdf09c09d Clean up formatting: Disallow space-before-tab. 2010-02-18 17:08:50 -05:00
Nick Mathewson
7515de91fe When connect() succeeds immediately, don't invoke the callback immediately.
We need this to get unit tests to pass on freebsd.
2010-02-18 14:50:44 -05:00
Nick Mathewson
ff3f6cd42b Check more internal event_add() calls for failure
Most of these should be unable to fail, since adding a timeout
generally always works.  Still, it's better not to try to be "too
smart for our own good here."

There are some remaining event_add() calls that I didn't add checks
for; I've marked those with "XXXX" comments.
2010-01-22 16:14:49 -05:00
Nick Mathewson
ba2945f931 Merge branch 'ratelimit'
Conflicts:
	bufferevent_async.c
2010-01-06 17:59:44 -05:00
Nick Mathewson
2e8eeea3e8 Fix crash bugs when a bufferevent's eventcb is not set.
In many places throughout the code, we called _bufferevent_run_eventcb
without checking whether the eventcb was actually set.  This would
work fine when the bufferevent's callbacks were deferred, but
otherwise the code would segfault.  Strangely, we always remembered to
check before calling the _bufferevent_run_{read,write}cb functions.

To prevent similar errors in the future, all of
_buferevent_run_{read,write,event}cb now check to make sure the
callback is actually set before invoking or deferring the callback.
This patch also removes the now-redundant checks for {read,write}cb.
2009-12-29 19:50:03 -05:00
Nick Mathewson
82743794d3 Do not make bufferevent_setfd implicitly disable EV_READ and EV_WRITE.
This obviates the need for BEV_SUSPEND_CONNECTING, and good riddance.
2009-12-28 16:59:07 -05:00
Nick Mathewson
737c9cd87b Rate-limiting for bufferevents; group and individual limits are supported.
The fairness algorithms are not the best, not every bufferevent type
is supported, and some of the locking tricks here are simply absurd.
Still, this code should be a good first step.
2009-12-28 16:11:18 -05:00
Nick Mathewson
4a5b53432b Do not ignore bufferevent_enable(EV_READ) before bufferevent_connect().
Previously, we weren't remembering that we wanted to re-add the read
event once the connect was finished.  Now we are.
2009-12-23 07:48:43 -05:00
Nick Mathewson
cf749e227c Add a temporary workaround for an ssl bug found on FreeBSD.
Basically, we only want to report the 'connected' event because of
the socket connect() finishing when we have an actual socket
bufferevent; on an SSL bufferevent, 'connected' means 'SSL
connection finished.'

This isn't FreeBSD's fault: it just has a connect() that tends to
succeed pretty early.

svn:r1548
2009-11-18 21:16:53 +00:00
Nick Mathewson
d7d1f1da09 Move responsibility for IOCP callback into bufferevent_async.
This patch from Chris Davis saves some callback depth, and adds proper
ref-counting to bufferevents when there's a deferred evbuffer callback
inflight.  It could use a couple more comments to really nail down what
its invariants are.

svn:r1543
2009-11-17 20:31:09 +00:00
Nick Mathewson
86f5742015 Add two implementations of getaddrinfo: one blocking and one nonblocking.
The entry points are evutil_getaddrinfo and evdns_getaddrinfo respectively.
There are fairly extensive unit tests.

I believe this code conforms to RFC3493 pretty closely, but there are
probably more issues.  It should get tested on more platforms.

This code means we can dump the well-intentioned but weirdly-implemented
bufferevent_evdns and evutil_resolve code.

svn:r1537
2009-11-16 22:25:46 +00:00
Nick Mathewson
784b8773a4 We do not work any more without an event-config.h; stop pretending that it is meaningful to check for HAVE_CONFIG_H
svn:r1516
2009-11-06 21:46:57 +00:00
Nick Mathewson
86db1c851b Commit ConnectEx code to get connect working with async bufferevents.
This is code by Chris Davis, with changes to get the unit tests failing less aggressively.

The unit tests for this code do not completely pass yet; Chris is looking into that.  If they aren't passing by the next release, I'll turn off this code.

svn:r1499
2009-11-04 05:19:26 +00:00
Nick Mathewson
6ca32df11a Add a missing include for win32.
svn:r1498
2009-11-04 03:54:05 +00:00
Nick Mathewson
0b9eb1bffb Add a bufferevent function to resolve a name then connect to it.
This function, bufferevent_socket_connect_hostname() can either use
evdns to do the resolve, or use a new function (evutil_resolve) that
uses getaddrinfo or gethostbyname, like http.c does now.

This function is meant to eventually replace the hostname resolution mess in
http.c.

svn:r1496
2009-11-03 20:40:48 +00:00
Nick Mathewson
2e36dbe1a6 Use EVUTIL_ASSERT() consistently instead of assert.
svn:r1464
2009-10-26 20:00:43 +00:00
Nick Mathewson
38aec9ec7c Tweaks to IOCP interface.
svn:r1461
2009-10-23 22:38:35 +00:00
Nick Mathewson
879420a711 Expose a narrow window to the IOCP code.
svn:r1459
2009-10-23 22:00:29 +00:00
Nick Mathewson
b73ad7bc45 Treat the bitwise OR of two enum values as an int.
This makes our interfaces usable from C++, which doesn't believe
you can say    "bufferevent_socket_nase(base, -1,
BEV_OPT_CLOSE_ON_FREE|BEV_OPT_DEFER_CALLBACKS)" but which instead
would demand "static_cast<bufferevent_options>(BEV_OPT_CLOSE_ON_FREE|
BEV_OPT_DEFER_CALLBACKS))" for the last	argument.

Diagnosis and patch from Chris Davis.

svn:r1456
2009-10-21 18:48:22 +00:00
Nick Mathewson
e3fd294a6d Spelling fixes in comments and strings.
svn:r1445
2009-10-16 13:19:57 +00:00
Nick Mathewson
25af695441 When a bufferevent_connect() call fails, give the client an error callback.
Patch from Christopher Davis.

svn:r1444
2009-10-14 00:46:47 +00:00
Nick Mathewson
f65b8b0964 On connect, call only one of BEV_EVENT_CONNECTED or writecb.
Previously, if we had a socket bufferevent in connect state, we'd send
both of these to indicate that the connection was done.  That was broken
since the point of adding BEV_EVENT_CONNECTED was so that we could
distinguish "we're connected" and "we wrote something".

Now, writecb is called only when
   A) the connection finished but the user never put the socket into a
      "connecting" state, or
   B) data was actually written.

svn:r1425
2009-08-19 20:55:25 +00:00
Nick Mathewson
eff09a299c tab/whitespace fixes in bufferevent_sock.c
Also note that write() doesn't usually say 0.

svn:r1414
2009-08-14 20:06:48 +00:00
Nick Mathewson
800f9aa607 When bufferevent_socket_connect is called with no address, assume that our existing fd is connecting and put the connection into "connecting" mode.
svn:r1411
2009-08-09 20:17:29 +00:00
Nick Mathewson
d1a2254bf2 Fix some bugs in bufferevent_socket_connect
svn:r1398
2009-07-30 20:41:31 +00:00
Nick Mathewson
709c21c48c Bufferevent support for openssl.
This code adds a new Bufferevent type that is only compiled when the
openssl library is present.  It supports using an SSL object and an
event alert mechanism, which can either be an fd or an underlying
bufferevent.

There is still more work to do: the unit tests are incomplete, and we
need to support flush and shutdown much better.  Sometimes events are
generated needlessly: this will hose performance.

There's a new encrypting proxy in sample/le-proxy.c.

This code has only been tested on OSX, and nowhere else.

svn:r1382
2009-07-28 04:03:57 +00:00
Nick Mathewson
a62283a9c3 Always hold a reference to a bufferevent when calling its callbacks.
Rationale: we hold a lock on the bufferevent when its callbacks are
executing, so we need to release the lock afterwards.  But the
callback might free the bufferevent, so unless we're holding a
reference on the bufferevent, the lock might not be there for us to
release.

svn:r1347
2009-07-17 17:46:17 +00:00
Nick Mathewson
a501d6833b Add a lock/unlock pair inside the event callbacks in bufferevents.
This fixes part of bug 2800642, I believe, though there is still a
general race condition in multithreaded use of events that we need to
think about.

svn:r1337
2009-07-10 19:34:00 +00:00
Nick Mathewson
5232cfa357 Consistently say "eventcb" instead of "errorcb"
svn:r1316
2009-05-25 23:11:20 +00:00
Nick Mathewson
31d89f274b Add a "ctrl" mechanism to bufferevents for property access.
OpenSSL uses something like this to implement get/set access for
properties on its BIOs, so that it doesn't need to add a pair of
get/set functions to the vtable struct for every new abstract property
it provides an accessor for.

Doing this lets us make bufferevent_setfd abstract, and implement an
abstract bufferevent_getfd.

svn:r1284
2009-05-13 20:37:21 +00:00