Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
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	[thread overview]
Message-ID: <2538f308697f39260ae29713bd765ad00c101f93.1556663421.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1556663421.git.v.shpilevoy@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)

  parent reply	other threads:[~2019-04-30 22:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-30 22:31 [tarantool-patches] [PATCH 0/5] swim lua preparation Vladislav Shpilevoy
2019-04-30 22:31 ` [tarantool-patches] [PATCH 1/5] swim: do not use ev_timer_start Vladislav Shpilevoy
2019-05-01  5:09   ` [tarantool-patches] " Konstantin Osipov
2019-04-30 22:31 ` [tarantool-patches] [PATCH 2/5] swim: introduce member reference API Vladislav Shpilevoy
2019-05-01  5:15   ` [tarantool-patches] " Konstantin Osipov
2019-05-02 15:10     ` Vladislav Shpilevoy
2019-05-02 15:46       ` Konstantin Osipov
2019-05-02 17:32         ` Vladislav Shpilevoy
2019-04-30 22:31 ` [tarantool-patches] [PATCH 3/5] sio: return 'no host' flag from sio_uri_to_addr() Vladislav Shpilevoy
2019-05-01  5:18   ` [tarantool-patches] " Konstantin Osipov
2019-04-30 22:31 ` [tarantool-patches] [PATCH 4/5] swim: allow to omit host in URI Vladislav Shpilevoy
2019-05-01  5:20   ` [tarantool-patches] " Konstantin Osipov
2019-05-02 15:10     ` Vladislav Shpilevoy
2019-04-30 22:31 ` Vladislav Shpilevoy [this message]
2019-05-01  5:21   ` [tarantool-patches] Re: [PATCH 5/5] swim: explicitly stop old ev_io input/output on rebind Konstantin Osipov
2019-05-02 17:32 ` [tarantool-patches] Re: [PATCH 0/5] swim lua preparation Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2538f308697f39260ae29713bd765ad00c101f93.1556663421.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 5/5] swim: explicitly stop old ev_io input/output on rebind' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox