1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

added a test event loop

(This used to be ctdb commit 0a07269cc5e44f47352ac39170ce4cb9b400055f)
This commit is contained in:
Andrew Tridgell 2006-11-18 15:27:36 +11:00
parent 767dec9f62
commit 9ef0cfa2e9
2 changed files with 25 additions and 4 deletions

View 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);
}

View 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();