[zeromq-dev] tcp_connecter.cpp didn't handle the interrupted connect.
Pieter Hintjens
ph at imatix.com
Sun Jun 24 08:26:24 CEST 2012
Hi Kaka,
Thanks for this suggestion.
Please see http://www.zeromq.org/docs:contributing for how to make
changes to 0MQ.
-Pieter
On Thu, Jun 21, 2012 at 7:07 AM, kaka chen <kaka11.chen at gmail.com> wrote:
> From the source code of zeromq, I think tcp_connecter.cpp didn't handle the
> interrupted connect.
> From Unix Network Programming Volume1 3rd edition
> Page75:
> Interrupted connect
> What happens if our call to connect on a normal blocking socket is
> interrupted, say, by a caught signal,
> before TCP's three-way handshake completes? Assuming the connect is not
> automatically restarted, it
> returns EINTR. But, we cannot call connect again to wait for the connection
> to complete. Doing so will
> return EADDRINUSE.
> What we must do in this scenario is call select, just as we have done in
> this section for a nonblocking
> connect. select returns when the connection completes successfully (making
> the socket writable) or
> when the connection fails (making the socket readable and writable).
> Therefore if I am right, the following is the patch for zeromq-3.2.0-rc1, if
> it is ok, I can pull a request buy git-hub if necessary,
> thanks!
>
> Kaka Chen
>
> --- src/tcp_connecter.cpp 2012-06-05 15:39:30.000000000 +0800
> +++ src/tcp_connecter.cpp 2012-06-21 13:09:08.070439360 +0800
> @@ -95,7 +95,11 @@
>
> void zmq::tcp_connecter_t::out_event ()
> {
> - fd_t fd = connect ();
> + bool is_interruped = false;
> + fd_t fd = connect (&is_interruped);
> + if (is_interruped) {
> + return;
> + }
> rm_fd (handle);
> handle_valid = false;
>
> @@ -233,8 +237,9 @@
> return -1;
> }
>
> -zmq::fd_t zmq::tcp_connecter_t::connect ()
> +zmq::fd_t zmq::tcp_connecter_t::connect (bool *is_interrupted)
> {
> + is_interrupted = false;
> // Async connect have finished. Check whether an error occured.
> int err = 0;
> #if defined ZMQ_HAVE_HPUX
> @@ -264,6 +269,10 @@
> err = errno;
> if (err != 0) {
> errno = err;
> + if (errno == EINTR) {
> + *is_interrupted = true;
> + return s;
> + }
> errno_assert (errno == ECONNREFUSED || errno == ECONNRESET ||
> errno == ETIMEDOUT || errno == EHOSTUNREACH ||
> errno == ENETUNREACH || errno == ENETDOWN);
>
> --- src/tcp_connecter.hpp 2012-06-05 15:39:30.000000000 +0800
> +++ src/tcp_connecter.hpp 2012-06-21 13:08:16.732028506 +0800
> @@ -80,7 +80,7 @@
>
> // Get the file descriptor of newly created connection. Returns
> // retired_fd if the connection was unsuccessfull.
> - fd_t connect ();
> + fd_t connect (bool *is_interruped);
>
> // Address to connect to. Owned by session_base_t.
> const address_t *addr;
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
More information about the zeromq-dev
mailing list