synk

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

commit b3dca9f5dc37c9e6190b5f6532ce9099b49ad2e7
parent 01aea7ee2faa01002207932529972d3c491dfca1
Author: Willy <willyatmailoodotorg>
Date:   Tue Aug 16 20:36:27 +0200

Remove dependency to pthreads

Diffstat:
config.mk | 2+-
mkfile | 4+---
synk.c | 32++++++++++++++------------------
3 files changed, 16 insertions(+), 22 deletions(-)
diff --git a/config.mk b/config.mk @@ -9,4 +9,4 @@ MANDIR = ${PREFIX}/man CPPFLAGS = -DVERSION=\"${VERSION}\" CFLAGS = ${CPPFLAGS} -Wall -Wextra -pedantic -g LDFLAGS = -LIBS = -lpthread +LIBS = diff --git a/mkfile b/mkfile @@ -1,8 +1,6 @@ <config.mk -all:V: synk - -%: %.o +synk: synk.o $LD -o $target $prereq $LDFLAGS $LIBS %.o: %.c diff --git a/synk.c b/synk.c @@ -1,5 +1,4 @@ #include <limits.h> -#include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -33,14 +32,13 @@ usage(char *name) exit(1); } -void * -handleclient(void *arg) +int +handleclient(struct client_t *c) { int i = 0; char path[PATH_MAX] = "", ts[32] = ""; size_t len = 0; struct stat sb; - struct client_t *c = *(struct client_t **)arg; printf("%s: connected\n", inet_ntoa(c->in)); while ((len = read(c->fd, &path, PATH_MAX)) > 0) { @@ -62,8 +60,8 @@ handleclient(void *arg) close(c->fd); len = 0; printf("%s: disconnected\n", inet_ntoa(c->in)); - free(c); - pthread_exit((int *)&len); + + return 0; } int @@ -75,7 +73,6 @@ server(in_addr_t host, in_port_t port) struct sockaddr_in clt; struct sockaddr_in srv; struct client_t *c = NULL; - pthread_t th; if ((sfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("socket"); @@ -97,19 +94,18 @@ server(in_addr_t host, in_port_t port) return 1; } - for (;;) { - len = sizeof(clt); - if ((cfd = accept(sfd, (struct sockaddr *)&clt, &len)) < 0) { - perror("accept"); - return 1; - } + 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; + c = malloc(sizeof(struct client_t)); + c->fd = cfd; + c->in = clt.sin_addr; - pthread_create(&th, NULL, handleclient, &c); - } + handleclient(c); + free(c); return 0; }