]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix ssl utils and lua tcp
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 21 Jun 2019 16:58:44 +0000 (17:58 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 22 Jun 2019 09:57:29 +0000 (10:57 +0100)
src/libutil/ssl_util.c
src/lua/lua_tcp.c

index 0fe6cc625d6ffc2edf3953613bcfffebcc59886a..7d4612b3d4b07515cdb3328c4915d7d21d1bd25c 100644 (file)
@@ -436,6 +436,7 @@ rspamd_ssl_event_handler (gint fd, short what, gpointer ud)
                                what = EV_WRITE;
                        }
                        else {
+                               rspamd_ev_watcher_stop (c->event_loop, c->ev);
                                rspamd_tls_set_error (ret, "connect", &err);
                                c->err_handler (c->handler_data, err);
                                g_error_free (err);
@@ -453,11 +454,12 @@ rspamd_ssl_event_handler (gint fd, short what, gpointer ud)
                break;
        case ssl_next_write:
        case ssl_conn_connected:
-               rspamd_ev_watcher_reschedule (c->event_loop, c->ev, EV_WRITE);
+               rspamd_ev_watcher_reschedule (c->event_loop, c->ev, what);
                c->state = ssl_conn_connected;
-               c->handler (fd, EV_WRITE, c->handler_data);
+               c->handler (fd, what, c->handler_data);
                break;
        default:
+               rspamd_ev_watcher_stop (c->event_loop, c->ev);
                g_set_error (&err, rspamd_ssl_quark (), EINVAL,
                                "ssl bad state error: %d", c->state);
                c->err_handler (c->handler_data, err);
index b45d5b64561ce6313c802d07ccdb43c2cbf6b968..e2f55e78b3c8fb7fd02822a9f02326de7cc19c67 100644 (file)
@@ -64,7 +64,7 @@ rspamd_config:register_symbol({
     end
     local function from_done_cb(err, data, conn)
       logger.errx(task, 'FROM: got reply: %s, error: %s', data, err)
-      conn:add_write(rcpt_cb, 'RCPT TO: <hui@yandex.ru>\r\n')
+      conn:add_write(rcpt_cb, 'RCPT TO: <test@yandex.ru>\r\n')
     end
     local function from_cb(err, conn)
       logger.errx(task, 'written from, error: %s', err)
@@ -281,7 +281,7 @@ struct lua_tcp_write_handler {
 enum lua_tcp_handler_type {
        LUA_WANT_WRITE = 0,
        LUA_WANT_READ,
-       LUA_WANT_CONNECT // used only with sync connections
+       LUA_WANT_CONNECT
 };
 
 struct lua_tcp_handler {
@@ -1007,6 +1007,8 @@ lua_tcp_handler (int fd, short what, gpointer ud)
        struct lua_tcp_handler *rh = g_queue_peek_head (cbd->handlers);
        event_type = rh->type;
 
+       rspamd_ev_watcher_stop (cbd->event_loop, &cbd->ev);
+
        if (what == EV_READ) {
                if (cbd->ssl_conn) {
                        r = rspamd_ssl_read (cbd->ssl_conn, inbuf, sizeof (inbuf));
@@ -1074,12 +1076,6 @@ lua_tcp_handler (int fd, short what, gpointer ud)
                        g_assert_not_reached ();
                }
        }
-#ifdef EV_CLOSED
-       else if (what == EV_CLOSED) {
-               lua_tcp_push_error (cbd, TRUE, "Remote peer has closed the connection");
-               TCP_RELEASE (cbd);
-       }
-#endif
        else {
                lua_tcp_push_error (cbd, TRUE, "IO timeout");
                TCP_RELEASE (cbd);
@@ -1120,16 +1116,17 @@ lua_tcp_plan_handler_event (struct lua_tcp_cbdata *cbd, gboolean can_read,
                                }
                        }
                        else {
-                               msg_debug_tcp ("plan new read");
                                if (can_read) {
                                        /* We need to plan a new event */
+                                       msg_debug_tcp ("plan new read");
                                        rspamd_ev_watcher_reschedule (cbd->event_loop, &cbd->ev,
                                                        EV_READ);
                                }
                                else {
                                        /* Cannot read more */
+                                       msg_debug_tcp ("cannot read more");
                                        lua_tcp_push_error (cbd, FALSE, "EOF, cannot read more data");
-                                       if (!IS_SYNC(cbd)) {
+                                       if (!IS_SYNC (cbd)) {
                                                lua_tcp_shift_handler (cbd);
                                                lua_tcp_plan_handler_event (cbd, can_read, can_write);
                                        }
@@ -1275,7 +1272,7 @@ lua_tcp_make_connection (struct lua_tcp_cbdata *cbd)
                }
        }
        else {
-               rspamd_ev_watcher_init (&cbd->ev, cbd->fd, EV_READ|EV_WRITE,
+               rspamd_ev_watcher_init (&cbd->ev, cbd->fd, EV_WRITE,
                                lua_tcp_handler, cbd);
                lua_tcp_register_event (cbd);
                lua_tcp_plan_handler_event (cbd, TRUE, TRUE);