tinywebd

changeset 8:121b991ccc1d

fixed the SIGPIPE bug
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 17 Apr 2015 12:02:59 +0300
parents 5ec50ca0d071
children 0244b08cc9d3
files src/main.c src/tinyweb.c
diffstat 2 files changed, 14 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/src/main.c	Fri Apr 17 11:45:08 2015 +0300
     1.2 +++ b/src/main.c	Fri Apr 17 12:02:59 2015 +0300
     1.3 @@ -94,6 +94,12 @@
     1.4  				}
     1.5  				break;
     1.6  
     1.7 +			case 'c':
     1.8 +				if(tw_set_root(argv[++i]) == -1) {
     1.9 +					return -1;
    1.10 +				}
    1.11 +				break;
    1.12 +
    1.13  			case 'h':
    1.14  				print_help(argv[0]);
    1.15  				exit(0);
     2.1 --- a/src/tinyweb.c	Fri Apr 17 11:45:08 2015 +0300
     2.2 +++ b/src/tinyweb.c	Fri Apr 17 12:02:59 2015 +0300
     2.3 @@ -124,11 +124,6 @@
     2.4  {
     2.5  	struct client *c, dummy;
     2.6  
     2.7 -	if(!socks) {
     2.8 -		/* just return the count */
     2.9 -		return num_clients + 1;	/* +1 for the listening socket */
    2.10 -	}
    2.11 -
    2.12  	/* first cleanup the clients marked for removal */
    2.13  	dummy.next = clist;
    2.14  	c = &dummy;
    2.15 @@ -147,6 +142,12 @@
    2.16  	}
    2.17  	clist = dummy.next;
    2.18  
    2.19 +
    2.20 +	if(!socks) {
    2.21 +		/* just return the count */
    2.22 +		return num_clients + 1;	/* +1 for the listening socket */
    2.23 +	}
    2.24 +
    2.25  	/* go through the client list and populate the array */
    2.26  	maxfd = lis;
    2.27  	*socks++ = lis;
    2.28 @@ -210,6 +211,7 @@
    2.29  	c->bufsz = 0;
    2.30  	c->next = clist;
    2.31  	clist = c;
    2.32 +	++num_clients;
    2.33  	return 0;
    2.34  }
    2.35  
    2.36 @@ -364,6 +366,7 @@
    2.37  				int sz = cont_left < 4096 ? cont_left : 4096;
    2.38  				send(c->s, ptr, sz, 0);
    2.39  				ptr += sz;
    2.40 +				cont_left -= sz;
    2.41  			}
    2.42  
    2.43  			munmap(cont, st.st_size);