synk

synchronize files between hosts
Log | Files | Refs | README | LICENSE

commit 78511ee61482c9fbf336fa601f841113a5544d1e
parent e355d45e1f7b7db572874e8e0a5770470a42a0a6
Author: Willy <willyatmailoodotorg>
Date:   Tue Aug 16 14:00:33 +0200

synkd: move server part into a function

Diffstat:
synkd.c | 44+++++++++++++++++++-------------------------
1 file changed, 19 insertions(+), 25 deletions(-)
diff --git a/synkd.c b/synkd.c @@ -26,7 +26,7 @@ usage(char *name) { } void * -handle_client(void *arg) +handleclient(void *arg) { int i = 0; char path[PATH_MAX] = "", ts[32] = ""; @@ -59,35 +59,16 @@ handle_client(void *arg) } int -loop(int sfd) +server(in_addr_t host, in_port_t port) { + int sfd; int cfd; socklen_t len; struct sockaddr_in clt; + struct sockaddr_in srv; struct client_t *c = NULL; pthread_t th; - for (;;) { - len = sizeof(clt); - if ((cfd = accept(sfd, (struct sockaddr *)&clt, &len)) < 0) { - perror("accept"); - return 1; - } - - c = malloc(sizeof(struct client_t)); - c->fd = cfd; - c->in = clt.sin_addr; - - pthread_create(&th, NULL, handle_client, &c); - } -} - -int -server(in_addr_t host, in_port_t port) -{ - int sfd; - struct sockaddr_in srv; - if ((sfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("socket"); return 1; @@ -108,7 +89,20 @@ server(in_addr_t host, in_port_t port) return 1; } - return loop(sfd); + for (;;) { + len = sizeof(clt); + if ((cfd = accept(sfd, (struct sockaddr *)&clt, &len)) < 0) { + perror("accept"); + return 1; + } + + c = malloc(sizeof(struct client_t)); + c->fd = cfd; + c->in = clt.sin_addr; + + pthread_create(&th, NULL, handleclient, &c); + } + return 0; } int @@ -129,5 +123,5 @@ main(int argc, char *argv[]) server(host, port); - return 0; + return 0; /* NOTREACHED */ }