summaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-04-23 14:48:34 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-04-23 14:48:34 +0100
commitabeb180044e33c529d1aa736958321d2e0ef11ec (patch)
tree7d376101fc1db956bf0d832db114d7ae792bc582 /src/libutil
parent08ca16a01e7a39cd733f1de6cf77c81fd7ad6e2d (diff)
downloadrspamd-abeb180044e33c529d1aa736958321d2e0ef11ec.tar.gz
rspamd-abeb180044e33c529d1aa736958321d2e0ef11ec.zip
Fix issue with read event in http server.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/http.c18
-rw-r--r--src/libutil/http.h1
2 files changed, 18 insertions, 1 deletions
diff --git a/src/libutil/http.c b/src/libutil/http.c
index b360a5a1d..1b635b44f 100644
--- a/src/libutil/http.c
+++ b/src/libutil/http.c
@@ -505,6 +505,7 @@ rspamd_http_on_message_complete (http_parser* parser)
if (ret == 0) {
rspamd_http_connection_ref (conn);
ret = conn->finish_handler (conn, priv->msg);
+ conn->finished = TRUE;
rspamd_http_connection_unref (conn);
}
@@ -565,6 +566,7 @@ rspamd_http_write_helper (struct rspamd_http_connection *conn)
if (priv->wr_pos >= priv->wr_total) {
rspamd_http_connection_ref (conn);
conn->finish_handler (conn, priv->msg);
+ conn->finished = TRUE;
rspamd_http_connection_unref (conn);
}
else {
@@ -593,6 +595,18 @@ rspamd_http_event_handler (int fd, short what, gpointer ud)
g_error_free (err);
return;
}
+ else if (r == 0) {
+ if (conn->finished) {
+ rspamd_http_connection_unref (conn);
+ return;
+ }
+ else {
+ err = g_error_new (HTTP_ERROR, errno, "IO read error: unexpected EOF");
+ conn->error_handler (conn, err);
+ g_error_free (err);
+ return;
+ }
+ }
else {
buf->len = r;
rspamd_http_connection_ref (conn);
@@ -643,6 +657,7 @@ rspamd_http_connection_new (rspamd_http_body_handler_t body_handler,
new->finish_handler = finish_handler;
new->fd = -1;
new->ref = 1;
+ new->finished = FALSE;
/* Init priv */
priv = g_slice_alloc0 (sizeof (struct rspamd_http_connection_private));
@@ -674,7 +689,7 @@ rspamd_http_connection_reset (struct rspamd_http_connection *conn)
rspamd_http_message_free (msg);
priv->msg = NULL;
}
-
+ conn->finished = FALSE;
/* Clear priv */
event_del (&priv->ev);
if (priv->buf != NULL) {
@@ -862,6 +877,7 @@ rspamd_http_connection_write_message (struct rspamd_http_connection *conn,
priv->out[i++].iov_len = bodylen;
}
+ event_del (&priv->ev);
event_set (&priv->ev, fd, EV_WRITE, rspamd_http_event_handler, conn);
event_base_set (base, &priv->ev);
event_add (&priv->ev, priv->ptv);
diff --git a/src/libutil/http.h b/src/libutil/http.h
index 8af4429c6..a76135616 100644
--- a/src/libutil/http.h
+++ b/src/libutil/http.h
@@ -101,6 +101,7 @@ struct rspamd_http_connection {
gpointer ud;
enum rspamd_http_options opts;
enum rspamd_http_connection_type type;
+ gboolean finished;
gint fd;
gint ref;
};