Rename fd to listenfd for readability

Avoid confusion in functions that use 'fd' and shadow the
global fd.
This commit is contained in:
sin 2014-08-21 23:11:23 +01:00 committed by FRIGN
parent de74d9b8fe
commit 29c8cfa201

18
quark.c
View file

@ -97,7 +97,7 @@ static char reqbuf[MAXBUFLEN];
static char resbuf[MAXBUFLEN]; static char resbuf[MAXBUFLEN];
static char reqhost[256]; static char reqhost[256];
static char reqmod[256]; static char reqmod[256];
static int fd = -1; static int listenfd = -1;
static Request req; static Request req;
char * char *
@ -555,7 +555,7 @@ sighandler(int sig) {
while(0 < waitpid(-1, NULL, WNOHANG)); while(0 < waitpid(-1, NULL, WNOHANG));
} else { } else {
logerrmsg("info\tsignal %s, closing down\n", strsignal(sig)); logerrmsg("info\tsignal %s, closing down\n", strsignal(sig));
close(fd); close(listenfd);
running = 0; running = 0;
} }
} }
@ -637,15 +637,15 @@ main(int argc, char *argv[]) {
logerrmsg("error\tgetaddrinfo: %s\n", gai_strerror(i)); logerrmsg("error\tgetaddrinfo: %s\n", gai_strerror(i));
goto err; goto err;
} }
if ((fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1) { if ((listenfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1) {
logerrmsg("error\tsocket: %s\n", strerror(errno)); logerrmsg("error\tsocket: %s\n", strerror(errno));
goto err; goto err;
} }
if (bind(fd, ai->ai_addr, ai->ai_addrlen) == -1) { if (bind(listenfd, ai->ai_addr, ai->ai_addrlen) == -1) {
logerrmsg("error\tbind: %s\n", strerror(errno)); logerrmsg("error\tbind: %s\n", strerror(errno));
goto err; goto err;
} }
if (listen(fd, SOMAXCONN) == -1) { if (listen(listenfd, SOMAXCONN) == -1) {
logerrmsg("error\tlisten: %s\n", strerror(errno)); logerrmsg("error\tlisten: %s\n", strerror(errno));
goto err; goto err;
} }
@ -695,13 +695,13 @@ main(int argc, char *argv[]) {
logmsg("ready\t%s:%s\t%s\n", servername, serverport, docroot); logmsg("ready\t%s:%s\t%s\n", servername, serverport, docroot);
serve(fd); /* main loop */ serve(listenfd); /* main loop */
close(fd); close(listenfd);
freeaddrinfo(ai); freeaddrinfo(ai);
return EXIT_SUCCESS; return EXIT_SUCCESS;
err: err:
if (fd != -1) if (listenfd != -1)
close(fd); close(listenfd);
if (ai) if (ai)
freeaddrinfo(ai); freeaddrinfo(ai);
return EXIT_FAILURE; return EXIT_FAILURE;