[zeromq-dev] tcp_connecter.cpp didn't handle the interrupted connect.
kaka chen
kaka11.chen at gmail.com
Thu Jun 21 07:07:49 CEST 2012
>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;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120621/e8dc4b10/attachment.htm>
More information about the zeromq-dev
mailing list