Permalink
Browse files

Sync levent

  • Loading branch information...
1 parent d18ca68 commit ce353649281a7de4a80b336003ae7ec05280b939 @jedisct1 committed Nov 29, 2010
@@ -33,8 +33,13 @@ Makefile.in
*.lo
*.la
+# ctags stuff
+TAGS
+
# Stuff made by our makefiles
libevent.pc
+libevent_pthreads.pc
+libevent_openssl.pc
## The initial / makes these files only get ignored in particular directories.
/autom4te.cache
@@ -56,16 +61,18 @@ libevent.pc
/depcomp
/config.h
/config.h.in
-/event-config.h
/install-sh
/libtool
/ltmain.sh
/missing
/stamp-h1
+/include/event2/event-config.h
+
/sample/dns-example
/sample/event-test
/sample/hello-world
+/sample/http-server
/sample/le-proxy
/sample/signal-test
/sample/time-test
@@ -1996,20 +1996,19 @@ get_n_bytes_readable_on_socket(evutil_socket_t fd)
int
evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
{
- struct evbuffer_chain *chain, **chainp;
+ struct evbuffer_chain **chainp;
int n;
int result;
#ifdef USE_IOVEC_IMPL
int nvecs, i, remaining;
#else
+ struct evbuffer_chain *chain;
unsigned char *p;
#endif
EVBUFFER_LOCK(buf);
- chain = buf->last;
-
if (buf->freeze_end) {
result = -1;
goto done;
@@ -426,6 +426,7 @@ be_filter_readcb(struct bufferevent *underlying, void *_me)
else
state = BEV_NORMAL;
+ /* XXXX use return value */
res = be_filter_process_input(bevf, state, &processed_any);
/* XXX This should be in process_input, not here. There are
@@ -1086,6 +1086,13 @@ be_openssl_destruct(struct bufferevent *bev)
bufferevent_free(bev_ssl->underlying);
bev_ssl->underlying = NULL;
}
+ } else {
+ evutil_socket_t fd = -1;
+ BIO *bio = SSL_get_wbio(bev_ssl->ssl);
+ if (bio)
+ fd = BIO_get_fd(bio, NULL);
+ if (fd >= 0)
+ evutil_closesocket(fd);
}
SSL_free(bev_ssl->ssl);
} else {
@@ -1134,11 +1141,8 @@ be_openssl_ctrl(struct bufferevent *bev,
if (bev_ssl->underlying)
return -1;
{
- int flag = 0;
BIO *bio;
- if (bev_ssl->bev.options & BEV_OPT_CLOSE_ON_FREE)
- flag = 1;
- bio = BIO_new_socket(data->fd, flag);
+ bio = BIO_new_socket(data->fd, 0);
SSL_set_bio(bev_ssl->ssl, bio, bio);
bev_ssl->fd_is_set = 1;
}
@@ -1294,7 +1298,6 @@ bufferevent_openssl_socket_new(struct event_base *base,
/* Does the SSL already have an fd? */
BIO *bio = SSL_get_wbio(ssl);
long have_fd = -1;
- const int shutdown_flag = !!(options & BEV_OPT_CLOSE_ON_FREE);
if (bio)
have_fd = BIO_get_fd(bio, NULL);
@@ -1311,12 +1314,12 @@ bufferevent_openssl_socket_new(struct event_base *base,
This is probably an error on our part. Fail. */
return NULL;
}
- (void) BIO_set_close(bio, shutdown_flag);
+ (void) BIO_set_close(bio, 0);
} else {
/* The SSL isn't configured with a BIO with an fd. */
if (fd >= 0) {
/* ... and we have an fd we want to use. */
- bio = BIO_new_socket(fd, shutdown_flag);
+ bio = BIO_new_socket(fd, 0);
SSL_set_bio(ssl, bio, bio);
} else {
/* Leave the fd unset. */
@@ -449,6 +449,7 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai,
}
/* XXX use the other addrinfos? */
+ /* XXX use this return value */
r = bufferevent_socket_connect(bev, ai->ai_addr, (int)ai->ai_addrlen);
_bufferevent_decref_and_unlock(bev);
evutil_freeaddrinfo(ai);
View
@@ -63,8 +63,8 @@ static void *epoll_init(struct event_base *);
static int epoll_dispatch(struct event_base *, struct timeval *);
static void epoll_dealloc(struct event_base *);
-const struct eventop epollops = {
- "epoll",
+static const struct eventop epollops_changelist = {
+ "epoll (with changelist)",
epoll_init,
event_changelist_add,
event_changelist_del,
@@ -75,6 +75,24 @@ const struct eventop epollops = {
EVENT_CHANGELIST_FDINFO_SIZE
};
+
+static int epoll_nochangelist_add(struct event_base *base, evutil_socket_t fd,
+ short old, short events, void *p);
+static int epoll_nochangelist_del(struct event_base *base, evutil_socket_t fd,
+ short old, short events, void *p);
+
+const struct eventop epollops = {
+ "epoll",
+ epoll_init,
+ epoll_nochangelist_add,
+ epoll_nochangelist_del,
+ epoll_dispatch,
+ epoll_dealloc,
+ 1, /* need reinit */
+ EV_FEATURE_ET|EV_FEATURE_O1,
+ 0
+};
+
#define INITIAL_NEVENT 32
#define MAX_NEVENT 4096
@@ -115,6 +133,11 @@ epoll_init(struct event_base *base)
}
epollop->nevents = INITIAL_NEVENT;
+ if ((base->flags & EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST) != 0 ||
+ ((base->flags & EVENT_BASE_FLAG_IGNORE_ENV) == 0 &&
+ evutil_getenv("EVENT_EPOLL_USE_CHANGELIST") != NULL))
+ base->evsel = &epollops_changelist;
+
evsig_init(base);
return (epollop);
@@ -145,19 +168,14 @@ epoll_op_to_string(int op)
}
static int
-epoll_apply_changes(struct event_base *base)
+epoll_apply_one_change(struct event_base *base,
+ struct epollop *epollop,
+ const struct event_change *ch)
{
- struct event_changelist *changelist = &base->changelist;
- struct epollop *epollop = base->evbase;
- struct event_change *ch;
struct epoll_event epev;
- int i;
- int op, events;
-
- for (i = 0; i < changelist->n_changes; ++i) {
- ch = &changelist->changes[i];
- events = 0;
+ int op, events = 0;
+ if (1) {
/* The logic here is a little tricky. If we had no events set
on the fd before, we need to set op="ADD" and set
events=the events we want to add. If we had any events set
@@ -166,7 +184,6 @@ epoll_apply_changes(struct event_base *base)
want to remain. But if we want to delete the last event,
we say op="DEL" and set events=the remaining events. What
fun!
-
*/
/* TODO: Turn this into a switch or a table lookup. */
@@ -237,7 +254,7 @@ epoll_apply_changes(struct event_base *base)
}
if (!events)
- continue;
+ return 0;
memset(&epev, 0, sizeof(epev));
epev.data.fd = ch->fd;
@@ -251,6 +268,7 @@ epoll_apply_changes(struct event_base *base)
if (epoll_ctl(epollop->epfd, EPOLL_CTL_ADD, ch->fd, &epev) == -1) {
event_warn("Epoll MOD(%d) on %d retried as ADD; that failed too",
(int)epev.events, ch->fd);
+ return -1;
} else {
event_debug(("Epoll MOD(%d) on %d retried as ADD; succeeded.",
(int)epev.events,
@@ -267,6 +285,7 @@ epoll_apply_changes(struct event_base *base)
if (epoll_ctl(epollop->epfd, EPOLL_CTL_MOD, ch->fd, &epev) == -1) {
event_warn("Epoll ADD(%d) on %d retried as MOD; that failed too",
(int)epev.events, ch->fd);
+ return -1;
} else {
event_debug(("Epoll ADD(%d) on %d retried as MOD; succeeded.",
(int)epev.events,
@@ -292,6 +311,7 @@ epoll_apply_changes(struct event_base *base)
change_to_string(ch->read_change),
ch->write_change,
change_to_string(ch->write_change));
+ return -1;
}
} else {
event_debug(("Epoll %s(%d) on fd %d okay. [old events were %d; read change was %d; write change was %d]",
@@ -303,8 +323,60 @@ epoll_apply_changes(struct event_base *base)
ch->write_change));
}
}
+ return 0;
+}
- return (0);
+static int
+epoll_apply_changes(struct event_base *base)
+{
+ struct event_changelist *changelist = &base->changelist;
+ struct epollop *epollop = base->evbase;
+ struct event_change *ch;
+
+ int r = 0;
+ int i;
+
+ for (i = 0; i < changelist->n_changes; ++i) {
+ ch = &changelist->changes[i];
+ if (epoll_apply_one_change(base, epollop, ch) < 0)
+ r = -1;
+ }
+
+ return (r);
+}
+
+static int
+epoll_nochangelist_add(struct event_base *base, evutil_socket_t fd,
+ short old, short events, void *p)
+{
+ struct event_change ch;
+ ch.fd = fd;
+ ch.old_events = old;
+ ch.read_change = ch.write_change = 0;
+ if (events & EV_WRITE)
+ ch.write_change = EV_CHANGE_ADD |
+ (events & EV_ET);
+ if (events & EV_READ)
+ ch.read_change = EV_CHANGE_ADD |
+ (events & EV_ET);
+
+ return epoll_apply_one_change(base, base->evbase, &ch);
+}
+
+static int
+epoll_nochangelist_del(struct event_base *base, evutil_socket_t fd,
+ short old, short events, void *p)
+{
+ struct event_change ch;
+ ch.fd = fd;
+ ch.old_events = old;
+ ch.read_change = ch.write_change = 0;
+ if (events & EV_WRITE)
+ ch.write_change = EV_CHANGE_DEL;
+ if (events & EV_READ)
+ ch.read_change = EV_CHANGE_DEL;
+
+ return epoll_apply_one_change(base, base->evbase, &ch);
}
static int
Oops, something went wrong.

0 comments on commit ce35364

Please sign in to comment.