aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2020-12-25 17:41:16 +0000
committerrodri <rgl@antares-labs.eu>2020-12-25 17:41:16 +0000
commit2b94a456d4ea0e1b7013505787914887dd994108 (patch)
treebf1ea027b059d3f829f01fbfc3a082e4278f9f6f
parent6b56dcfb94347af43b0213863b79bcee3530b742 (diff)
downloadechod-2b94a456d4ea0e1b7013505787914887dd994108.tar.gz
echod-2b94a456d4ea0e1b7013505787914887dd994108.tar.bz2
echod-2b94a456d4ea0e1b7013505787914887dd994108.zip
get rid of commented-out code and unnecessary locking.HEADmaster
-rw-r--r--main.c48
1 files 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);
}