From 2b94a456d4ea0e1b7013505787914887dd994108 Mon Sep 17 00:00:00 2001 From: rodri Date: Fri, 25 Dec 2020 17:41:16 +0000 Subject: get rid of commented-out code and unnecessary locking. --- main.c | 48 ++---------------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/main.c b/main.c index 01ab687..cff963e 100644 --- a/main.c +++ b/main.c @@ -20,50 +20,12 @@ enum { int lfd, ncpu; pthread_t *threads; -pthread_mutex_t attendlock; int debug; char *argv0; /* - * echo service as of rfc862 - */ -//void -//srvecho(int fd) -//{ -// char buf[8192]; -// int n; -// -// while((n = read(fd, buf, sizeof buf)) > 0) -// if(write(fd, buf, n) != n) -// return; -//} -// -//void* -//tmain(void *a) -//{ -// char caddr[128]; -// int cfd; -// -// for(;;){ -// pthread_mutex_lock(&attendlock); -// if((cfd = acceptcall(lfd, caddr, sizeof caddr)) < 0) -// sysfatal("acceptcall: %r"); -// pthread_mutex_unlock(&attendlock); -// -// if(debug) -// fprint(2, "thr#%lu accepted call from %s\n", pthread_self(), caddr); -// -// srvecho(cfd); -// close(cfd); -// -// if(debug) -// fprint(2, "thr#%lu ended call with %s\n", pthread_self(), caddr); -// } -//} - -/* - * (udp)echo service as of rfc862 + * (udp)echo service as of rfc862, with echo+ support */ void* udpechosrv(void *a) @@ -82,12 +44,8 @@ udpechosrv(void *a) csalen = sizeof(sockaddr_in); for(;;){ - pthread_mutex_lock(&attendlock); - if((n = recvfrom(lfd, buf, sizeof buf, 0, (sockaddr*)&csa, &csalen)) < 0){ - pthread_mutex_unlock(&attendlock); + if((n = recvfrom(lfd, buf, sizeof buf, 0, (sockaddr*)&csa, &csalen)) < 0) continue; - } - pthread_mutex_unlock(&attendlock); clock_gettime(CLOCK_REALTIME, &ts); us = ts.tv_sec*1e6; @@ -153,7 +111,6 @@ main(int argc, char *argv[]) ncpu = 1; threads = emalloc(sizeof(pthread_t)*ncpu); - pthread_mutex_init(&attendlock, nil); for(i = 0; i < ncpu; i++){ pthread_create(threads+i, nil, udpechosrv, nil); @@ -164,6 +121,5 @@ main(int argc, char *argv[]) pause(); free(threads); - pthread_mutex_destroy(&attendlock); exit(0); } -- cgit v1.2.3