]> source.dussan.org Git - rspamd.git/commitdiff
Add support of buffered IO reset to support persistent connections.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 16 Feb 2012 13:13:09 +0000 (17:13 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 16 Feb 2012 13:13:09 +0000 (17:13 +0400)
src/buffer.c
src/buffer.h
src/fstring.c
src/fstring.h

index 2413fbbebf7f3a2bd19814f529639bee2c4788c1..764f82e396901f67445131882e5ebbba0e5b56c9 100644 (file)
@@ -353,12 +353,12 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read)
        }
 
        if (d->in_buf == NULL) {
-               d->in_buf = memory_pool_alloc (d->pool, sizeof (rspamd_buffer_t));
+               d->in_buf = memory_pool_alloc_tmp (d->pool, sizeof (rspamd_buffer_t));
                if (d->policy == BUFFER_LINE || d->policy == BUFFER_ANY) {
-                       d->in_buf->data = fstralloc (d->pool, BUFSIZ);
+                       d->in_buf->data = fstralloc_tmp (d->pool, BUFSIZ);
                }
                else {
-                       d->in_buf->data = fstralloc (d->pool, d->nchars + 1);
+                       d->in_buf->data = fstralloc_tmp (d->pool, d->nchars + 1);
                }
                d->in_buf->pos = d->in_buf->data->begin;
        }
@@ -634,7 +634,7 @@ rspamd_set_dispatcher_policy (rspamd_io_dispatcher_t * d, enum io_policy policy,
                /* Resize input buffer if needed */
                if (policy == BUFFER_CHARACTER && nchars != 0) {
                        if (d->in_buf && d->in_buf->data->size < nchars) {
-                               tmp = fstralloc (d->pool, d->nchars + 1);
+                               tmp = fstralloc_tmp (d->pool, d->nchars + 1);
                                memcpy (tmp->begin, d->in_buf->data->begin, d->in_buf->data->len);
                                t = d->in_buf->pos - d->in_buf->data->begin;
                                tmp->len = d->in_buf->data->len;
@@ -644,7 +644,7 @@ rspamd_set_dispatcher_policy (rspamd_io_dispatcher_t * d, enum io_policy policy,
                }
                else if (policy == BUFFER_LINE || policy == BUFFER_ANY) {
                        if (d->in_buf && d->nchars < BUFSIZ) {
-                               tmp = fstralloc (d->pool, BUFSIZ);
+                               tmp = fstralloc_tmp (d->pool, BUFSIZ);
                                memcpy (tmp->begin, d->in_buf->data->begin, d->in_buf->data->len);
                                t = d->in_buf->pos - d->in_buf->data->begin;
                                tmp->len = d->in_buf->data->len;
@@ -663,20 +663,23 @@ rspamd_dispatcher_write (rspamd_io_dispatcher_t * d, void *data, size_t len, gbo
 {
        rspamd_buffer_t                *newbuf;
 
-       newbuf = memory_pool_alloc (d->pool, sizeof (rspamd_buffer_t));
+       newbuf = memory_pool_alloc_tmp (d->pool, sizeof (rspamd_buffer_t));
        if (len == 0) {
                /* Assume NULL terminated */
                len = strlen ((gchar *)data);
        }
 
        if (!allocated) {
-               newbuf->data = fstralloc (d->pool, len);
+               newbuf->data = memory_pool_alloc_tmp (d->pool, sizeof (f_str_t));
+               newbuf->data->begin = memory_pool_alloc_tmp (d->pool, len);
+               newbuf->data->size = len;
+               newbuf->data->len = len;
 
                /* We need to copy data to temporary internal buffer to avoid using of stack variables */
                memcpy (newbuf->data->begin, data, len);
        }
        else {
-               newbuf->data = memory_pool_alloc (d->pool, sizeof (f_str_t));
+               newbuf->data = memory_pool_alloc_tmp (d->pool, sizeof (f_str_t));
                newbuf->data->begin = data;
                newbuf->data->size = len;
        }
@@ -742,6 +745,15 @@ rspamd_dispatcher_restore (rspamd_io_dispatcher_t * d)
        }
 }
 
+void
+rspamd_dispacther_cleanup (rspamd_io_dispatcher_t *d)
+{
+       g_queue_clear (d->out_buffers);
+       /* Cleanup temporary data */
+       memory_pool_cleanup_tmp (d->pool);
+       d->in_buf = NULL;
+}
+
 #undef debug_ip
 
 /* 
index 96e38d471cc89a6621160d34a4610bc3e7a8a1e8..ce2cf3d2ef0b8bfb06aa1eb13be0bb87f2a2be25 100644 (file)
@@ -123,4 +123,10 @@ void rspamd_dispatcher_restore (rspamd_io_dispatcher_t *d);
  */
 void rspamd_remove_dispatcher (rspamd_io_dispatcher_t *dispatcher);
 
+/**
+ * Cleanup dispatcher freeing all temporary data
+ * @param dispatcher pointer to dispatcher's object
+ */
+void rspamd_dispacther_cleanup (rspamd_io_dispatcher_t *dispatcher);
+
 #endif
index c2d48603b6f7defb7f799fbcb8602bc7f084abdf..b3050d8c2e8c4131b70de4936b733533c3e3043a 100644 (file)
@@ -272,6 +272,21 @@ fstralloc (memory_pool_t * pool, size_t len)
        return res;
 }
 
+/*
+ * Allocate memory for f_str_t from temporary pool
+ */
+f_str_t                        *
+fstralloc_tmp (memory_pool_t * pool, size_t len)
+{
+       f_str_t                        *res = memory_pool_alloc_tmp (pool, sizeof (f_str_t));
+
+       res->begin = memory_pool_alloc_tmp (pool, len);
+
+       res->size = len;
+       res->len = 0;
+       return res;
+}
+
 /*
  * Truncate string to its len
  */
index 566cbdc324b1a74f3a6116b7ed1b157a890acc2c..c55c3627a85824c43e991465abaebac94028210c 100644 (file)
@@ -78,6 +78,11 @@ gint fstrpush_unichar (f_str_t *dest, gunichar c);
  */
 f_str_t* fstralloc (memory_pool_t *pool, size_t len);
 
+/*
+ * Allocate memory for f_str_t from temporary pool
+ */
+f_str_t* fstralloc_tmp (memory_pool_t *pool, size_t len);
+
 /*
  * Truncate string to its len
  */