From 9ef0cfa2e93e3f08dc09c59b5dce12f462174786 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Nov 2006 15:27:36 +1100 Subject: [PATCH] added a test event loop (This used to be ctdb commit 0a07269cc5e44f47352ac39170ce4cb9b400055f) --- ctdb/ctdb_tcp.c | 21 +++++++++++++++++---- ctdb/ctdb_test.c | 8 ++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ctdb/ctdb_tcp.c b/ctdb/ctdb_tcp.c index 719e4babbb9..2327647753a 100644 --- a/ctdb/ctdb_tcp.c +++ b/ctdb/ctdb_tcp.c @@ -89,8 +89,15 @@ static void ctdb_node_connect_write(struct event_context *ev, struct fd_event *f socklen_t len; if (getsockopt(node->fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0 || - errno != 0) { + error != 0) { + if (error == EINPROGRESS) { + printf("connect in progress\n"); + return; + } + printf("getsockopt errno=%s\n", strerror(errno)); + talloc_free(fde); close(node->fd); + node->fd = -1; event_add_timed(ctdb->ev, node, timeval_current_ofs(1, 0), ctdb_node_connect, node); return; @@ -109,7 +116,7 @@ static void ctdb_node_connect_write(struct event_context *ev, struct fd_event *f static void ctdb_node_connect(struct event_context *ev, struct timed_event *te, struct timeval t, void *private) { - struct ctdb_node *node = talloc_get_type(node, struct ctdb_node); + struct ctdb_node *node = talloc_get_type(private, struct ctdb_node); struct ctdb_context *ctdb = node->ctdb; unsigned v; struct sockaddr_in sock_out; @@ -245,7 +252,9 @@ static void ctdb_incoming_read(struct event_context *ev, struct fd_event *fde, uint16_t flags, void *private) { struct ctdb_incoming *in = talloc_get_type(private, struct ctdb_incoming); + char c; printf("Incoming data\n"); + } @@ -258,13 +267,15 @@ static void ctdb_listen_event(struct event_context *ev, struct fd_event *fde, uint16_t flags, void *private) { struct ctdb_context *ctdb; - struct sockaddr addr; + struct sockaddr_in addr; socklen_t len; int fd; struct ctdb_incoming *in; ctdb = talloc_get_type(private, struct ctdb_context); - fd = accept(ctdb->listen_fd, &addr, &len); + memset(&addr, 0, sizeof(addr)); + len = sizeof(addr); + fd = accept(ctdb->listen_fd, (struct sockaddr *)&addr, &len); if (fd == -1) return; in = talloc(ctdb, struct ctdb_incoming); @@ -273,6 +284,8 @@ static void ctdb_listen_event(struct event_context *ev, struct fd_event *fde, event_add_fd(ctdb->ev, in, in->fd, EVENT_FD_READ, ctdb_incoming_read, in); + + printf("New incoming socket %d\n", in->fd); } diff --git a/ctdb/ctdb_test.c b/ctdb/ctdb_test.c index ce3b7b1ca9e..a0ef91966b9 100644 --- a/ctdb/ctdb_test.c +++ b/ctdb/ctdb_test.c @@ -151,6 +151,14 @@ int main(int argc, const char *argv[]) key.dptr = "test"; key.dsize = strlen("test")+1; + +#if 1 + /* loop for testing */ + while (1) { + event_loop_once(ev); + } +#endif + /* add some random data */ for (i=0;i<100;i++) { int v = random(); -- 2.47.3