From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id DB32E2D715 for ; Tue, 30 Apr 2019 18:31:31 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RDac7VB-fKJ7 for ; Tue, 30 Apr 2019 18:31:31 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 9A3F92C996 for ; Tue, 30 Apr 2019 18:31:31 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 5/5] swim: explicitly stop old ev_io input/output on rebind Date: Wed, 1 May 2019 01:31:27 +0300 Message-Id: <2538f308697f39260ae29713bd765ad00c101f93.1556663421.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: kostja@tarantool.org When an input/output file descriptor was changed, SWIM did this: swim_ev_io_set(io, new_fd) swim_ev_io_start(io) It worked in an assumption that libev allows to change fd on fly, and the tests were passing because fake event loop was used, not real libev. But it didn't work. Libev requires explicit ev_io_stop() called on the old descriptor. This patch makes this: swim_ev_io_stop(io) //do bind ... swim_ev_io_set(io, new_fd) swim_ev_io_start(io) Part of #3234 --- src/lib/swim/swim_io.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib/swim/swim_io.c b/src/lib/swim/swim_io.c index d49900a86..ef2f479eb 100644 --- a/src/lib/swim/swim_io.c +++ b/src/lib/swim/swim_io.c @@ -288,15 +288,18 @@ int swim_scheduler_bind(struct swim_scheduler *scheduler, const struct sockaddr_in *addr) { + swim_ev_io_stop(loop(), &scheduler->input); + swim_ev_io_stop(loop(), &scheduler->output); struct swim_transport *t = &scheduler->transport; - if (swim_transport_bind(t, (const struct sockaddr *) addr, - sizeof(*addr)) != 0) - return -1; - swim_ev_io_set(&scheduler->output, t->fd, EV_WRITE); - swim_ev_io_set(&scheduler->input, t->fd, EV_READ); - swim_ev_io_start(loop(), &scheduler->input); - swim_ev_io_start(loop(), &scheduler->output); - return 0; + int rc = swim_transport_bind(t, (const struct sockaddr *) addr, + sizeof(*addr)); + if (t->fd >= 0) { + swim_ev_io_set(&scheduler->output, t->fd, EV_WRITE); + swim_ev_io_set(&scheduler->input, t->fd, EV_READ); + swim_ev_io_start(loop(), &scheduler->input); + swim_ev_io_start(loop(), &scheduler->output); + } + return rc; } void -- 2.20.1 (Apple Git-117)