summaryrefslogtreecommitdiffstats
path: root/ctdb/tcp/tcp_connect.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-05-25 22:07:45 +1000
committerAndrew Tridgell <tridge@samba.org>2007-05-25 22:07:45 +1000
commit07ade57802a8e6182f2db1025f621154a65628fc (patch)
treed664a55111cafbcef90d4ae12a6d8c3def40e338 /ctdb/tcp/tcp_connect.c
parent31053286c568e039e178ddd7973a5f5ebdda684b (diff)
downloadsamba-07ade57802a8e6182f2db1025f621154a65628fc.tar.gz
samba-07ade57802a8e6182f2db1025f621154a65628fc.tar.xz
samba-07ade57802a8e6182f2db1025f621154a65628fc.zip
make sure we find out about new nodes as fast as possible
(This used to be ctdb commit 73f2c77166e2053625d0f76c370cf7e789a63fdf)
Diffstat (limited to 'ctdb/tcp/tcp_connect.c')
-rw-r--r--ctdb/tcp/tcp_connect.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/ctdb/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c
index 8a2f70c7b1..fa249d5fba 100644
--- a/ctdb/tcp/tcp_connect.c
+++ b/ctdb/tcp/tcp_connect.c
@@ -50,6 +50,7 @@ void ctdb_tcp_tnode_cb(uint8_t *data, size_t cnt, void *private_data)
/* start a new connect cycle to try to re-establish the
link */
ctdb_queue_set_fd(tnode->queue, -1);
+ tnode->fd = -1;
event_add_timed(node->ctdb->ev, node, timeval_zero(),
ctdb_tcp_node_connect, node);
}
@@ -69,6 +70,9 @@ static void ctdb_node_connect_write(struct event_context *ev, struct fd_event *f
socklen_t len = sizeof(error);
int one = 1;
+ talloc_free(tnode->connect_te);
+ tnode->connect_te = NULL;
+
if (getsockopt(tnode->fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0 ||
error != 0) {
talloc_free(fde);
@@ -120,6 +124,13 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
struct sockaddr_in sock_in;
struct sockaddr_in sock_out;
+ if (tnode->fd != -1) {
+ talloc_free(tnode->connect_fde);
+ tnode->connect_fde = NULL;
+ close(tnode->fd);
+ tnode->fd = -1;
+ }
+
tnode->fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
set_nonblocking(tnode->fd);
@@ -163,8 +174,15 @@ void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
}
/* non-blocking connect - wait for write event */
- event_add_fd(node->ctdb->ev, node, tnode->fd, EVENT_FD_WRITE|EVENT_FD_READ,
- ctdb_node_connect_write, node);
+ tnode->connect_fde = event_add_fd(node->ctdb->ev, node, tnode->fd,
+ EVENT_FD_WRITE|EVENT_FD_READ,
+ ctdb_node_connect_write, node);
+
+ /* don't give it long to connect - retry in one second. This ensures
+ that we find a node is up quickly (tcp normally backs off a syn reply
+ delay by quite a lot) */
+ tnode->connect_te = event_add_timed(ctdb->ev, node, timeval_current_ofs(1, 0),
+ ctdb_tcp_node_connect, node);
}
/*