tsynkd: move server part into a function - synk - synchronize files between hosts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 78511ee61482c9fbf336fa601f841113a5544d1e
 (DIR) parent e355d45e1f7b7db572874e8e0a5770470a42a0a6
 (HTM) Author: Willy <willyatmailoodotorg>
       Date:   Tue, 16 Aug 2016 14:00:33 +0200
       
       synkd: move server part into a function
       
       Diffstat:
         M synkd.c                             |      44 +++++++++++++------------------
       
       1 file changed, 19 insertions(+), 25 deletions(-)
       ---
 (DIR) diff --git a/synkd.c b/synkd.c
       t@@ -26,7 +26,7 @@ usage(char *name) {
        }
        
        void *
       -handle_client(void *arg)
       +handleclient(void *arg)
        {
                int i = 0;
                char path[PATH_MAX] = "", ts[32] = "";
       t@@ -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;
       t@@ -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
       t@@ -129,5 +123,5 @@ main(int argc, char *argv[])
                
                server(host, port);
        
       -        return 0;
       +        return 0; /* NOTREACHED */
        }