]> source.dussan.org Git - rspamd.git/commitdiff
Fix issue with read event in http server.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 23 Apr 2014 13:48:34 +0000 (14:48 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 23 Apr 2014 13:48:34 +0000 (14:48 +0100)
src/libutil/http.c
src/libutil/http.h

index b360a5a1df2830f34f880e02f48e89c304f1453e..1b635b44fa49483ce798ae702577f32b83880dae 100644 (file)
@@ -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);
index 8af4429c62b983d6e85da59d5b8bd9895453b9e9..a761356164056bd6e72f19a324dbb280deff08f0 100644 (file)
@@ -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;
 };