diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2007-02-26 12:09:22 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2007-02-26 12:09:22 +0000 |
commit | 03ffec58a714b14fc38a16d3f839b231743fe7ef (patch) | |
tree | 2dfa649d33bc380b5310c93bac7dde3329b609b6 /usr.sbin/relayd | |
parent | 52c6961ab92b67d820cf2103d3fa2ce0d5f99f16 (diff) |
improve the relay bufferevent handler if one side closed the connection
Diffstat (limited to 'usr.sbin/relayd')
-rw-r--r-- | usr.sbin/relayd/relay.c | 23 | ||||
-rw-r--r-- | usr.sbin/relayd/relayd.h | 3 |
2 files changed, 9 insertions, 17 deletions
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index 9bb2714fbb4..ad09876c52a 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.7 2007/02/26 11:59:48 reyk Exp $ */ +/* $OpenBSD: relay.c,v 1.8 2007/02/26 12:09:21 reyk Exp $ */ /* * Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org> @@ -860,7 +860,7 @@ relay_read_http(struct bufferevent *bev, void *arg) struct evbuffer *src = EVBUFFER_INPUT(bev); struct protonode *pn, pk, *pnv, pkv; char *line, buf[READ_BUF_SIZE], *ptr, *url, *method; - int done = 0, header = 0; + int header = 0; const char *errstr; size_t size; @@ -873,13 +873,13 @@ relay_read_http(struct bufferevent *bev, void *arg) pk.type = NODE_TYPE_HEADER; - while (!done && (line = evbuffer_readline(src)) != NULL) { + while (!cre->done && (line = evbuffer_readline(src)) != NULL) { /* * An empty line indicates the end of the request. * libevent already stripped the \r\n for us. */ if (!strlen(line)) { - done = 1; + cre->done = 1; free(line); break; } @@ -1005,7 +1005,7 @@ next: free(line); continue; } - if (done) { + if (cre->done) { RB_FOREACH(pn, proto_tree, &proto->tree) { if (cre->nodes[pn->id]) { cre->nodes[pn->id] = 0; @@ -1072,6 +1072,7 @@ next: cre->line = 0; cre->method = 0; cre->marked = 0; + cre->done = 0; if (proto->lateconnect && cre->dst->bev == NULL && relay_connect(con) == -1) { @@ -1094,30 +1095,20 @@ relay_error(struct bufferevent *bev, short error, void *arg) { struct ctl_relay_event *cre = (struct ctl_relay_event *)arg; struct session *con = (struct session *)cre->con; - struct evbuffer *src = EVBUFFER_OUTPUT(bev); struct evbuffer *dst; if (error & EVBUFFER_TIMEOUT) { relay_close(con, "buffer event timeout"); return; } -#if 0 - if (error & EVBUFFER_EOF) { - bufferevent_disable(bev, EV_READ|EV_WRITE); - relay_close(con, "done"); - return; - } -#endif if (error & (EVBUFFER_READ|EVBUFFER_WRITE|EVBUFFER_EOF)) { bufferevent_disable(bev, EV_READ|EV_WRITE); con->done = 1; if (cre->dst->bev != NULL) { dst = EVBUFFER_OUTPUT(cre->dst->bev); - if (EVBUFFER_LENGTH(dst)) { - bufferevent_write_buffer(cre->dst->bev, src); + if (EVBUFFER_LENGTH(dst)) return; - } } relay_close(con, "done"); diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h index fa4017ab41f..c386a144db4 100644 --- a/usr.sbin/relayd/relayd.h +++ b/usr.sbin/relayd/relayd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.h,v 1.32 2007/02/26 11:59:48 reyk Exp $ */ +/* $OpenBSD: relayd.h,v 1.33 2007/02/26 12:09:21 reyk Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -199,6 +199,7 @@ struct ctl_relay_event { int marked; int line; size_t toread; + int done; enum httpmethod method; u_int8_t *buf; |