]> source.dussan.org Git - rspamd.git/commitdiff
Release read lock lately.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 7 Nov 2011 16:58:54 +0000 (19:58 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 7 Nov 2011 16:58:54 +0000 (19:58 +0300)
src/buffer.c
src/kvstorage_server.c
src/kvstorage_server.h

index e647374c2562557619efc1bb6adff838f16d17fc..2413fbbebf7f3a2bd19814f529639bee2c4788c1 100644 (file)
@@ -187,6 +187,9 @@ write_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean is_delayed)
        len = g_queue_get_length (d->out_buffers);
        if (len > 1) {
                /* IOV version */
+
+               /* Unset delayed as actually we HAVE buffers to write */
+               is_delayed = TRUE;
                cur = d->out_buffers->tail;
                iov = g_slice_alloc (len * sizeof (struct iovec));
                i = 0;
index 370384159f388aa89f335c049ab5fc9bb197eea3..620c5c73f5c0937930949d5f50a85a73d555528c 100644 (file)
@@ -396,6 +396,8 @@ kvstorage_read_socket (f_str_t * in, void *arg)
                                        }
                                }
                                else {
+                                       session->elt = elt;
+
                                        if (!is_redis) {
                                                r = rspamd_snprintf (outbuf, sizeof (outbuf), "VALUE %s %ud %ud" CRLF,
                                                                ELT_KEY (elt), elt->flags, elt->size);
@@ -421,7 +423,10 @@ kvstorage_read_socket (f_str_t * in, void *arg)
                                                res = rspamd_dispatcher_write (session->dispather, CRLF,
                                                                sizeof (CRLF) - 1, FALSE, TRUE);
                                        }
-                                       g_static_rw_lock_reader_unlock (&session->cf->storage->rwlock);
+                                       if (!res) {
+                                               g_static_rw_lock_reader_unlock (&session->cf->storage->rwlock);
+                                       }
+
                                        return res;
                                }
                        }
@@ -525,6 +530,22 @@ kvstorage_read_socket (f_str_t * in, void *arg)
        return TRUE;
 }
 
+/*
+ * Called if buffers were written
+ */
+static gboolean
+kvstorage_write_socket (void *arg)
+{
+       struct kvstorage_session                        *session = (struct kvstorage_session *) arg;
+
+       if (session->elt) {
+               g_static_rw_lock_reader_unlock (&session->cf->storage->rwlock);
+               session->elt = NULL;
+       }
+
+       return TRUE;
+}
+
 /*
  * Called if something goes wrong
  */
@@ -573,8 +594,9 @@ thr_accept_socket (gint fd, short what, void *arg)
        session->thr = thr;
        session->sock = nfd;
        session->dispather = rspamd_create_dispatcher (thr->ev_base, nfd, BUFFER_LINE,
-                       kvstorage_read_socket, NULL,
+                       kvstorage_read_socket, kvstorage_write_socket,
                        kvstorage_err_socket, thr->tv, session);
+       session->elt = NULL;
 
        if (su.ss.ss_family == AF_UNIX) {
                session->client_addr.s_addr = INADDR_NONE;
index 4f9e8c9518cb641465da79dc42a7e6256cc583ed..3b475ebd0299c14bdb9cef8391c19ad6dfbc2504 100644 (file)
@@ -73,6 +73,7 @@ struct kvstorage_session {
        gchar *key;
        struct kvstorage_config *cf;
        struct kvstorage_worker_thread *thr;
+       struct rspamd_kv_element *elt;
        struct in_addr client_addr;
        gint sock;
        guint flags;