]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
added a test event loop
authorAndrew Tridgell <tridge@samba.org>
Sat, 18 Nov 2006 04:27:36 +0000 (15:27 +1100)
committerAndrew Tridgell <tridge@samba.org>
Sat, 18 Nov 2006 04:27:36 +0000 (15:27 +1100)
(This used to be ctdb commit 0a07269cc5e44f47352ac39170ce4cb9b400055f)

ctdb/ctdb_tcp.c
ctdb/ctdb_test.c

index 719e4babbb9c34abd6caaaf77b5a283ee68b5269..2327647753a2f4300cd996b62635a55ed10f74ff 100644 (file)
@@ -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);
 }
 
 
index ce3b7b1ca9ee518fe4bdb3f7aab034fd35ea884e..a0ef91966b9da3a5b377bd70cebb94c7e1225070 100644 (file)
@@ -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();