X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=cprogs%2Fwrbufcore.c;h=2c3769fa0b22448559e77aeed0a040e61cc7c9c4;hp=417cb01ac0cef44f7cc03c80f04f0120152fc857;hb=d9d8b1a736946ae91c521133dc32d5e1d6b5e506;hpb=e483a046db5ff0972702a0dc29ba4e00b698d997 diff --git a/cprogs/wrbufcore.c b/cprogs/wrbufcore.c index 417cb01..2c3769f 100644 --- a/cprogs/wrbufcore.c +++ b/cprogs/wrbufcore.c @@ -13,7 +13,7 @@ * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2, + * published by the Free Software Foundation; either version 3, * or (at your option) any later version. * * This is distributed in the hope that it will be useful, but @@ -30,19 +30,26 @@ #include "rwbuffer.h" static size_t waitfill; -static int writing; + +int writing; void wrbufcore_startup(void) { waitfill= (buffersize*3)/4; writing=0; + maxselfd=0; +} + +void fdsetset(int fd, fd_set *set) { + FD_SET(fd,set); + if (fd >= maxselfd) maxselfd= fd+1; } void wrbufcore_prepselect(int rdfd, int wrfd) { FD_ZERO(&readfds); - if (rdfd>=0 && !seeneof && used+1=0 && !seeneof && used+1=0 && FD_ISSET(rdfd,&readfds)) && !used) { + wrbuf_report("stopping"); writing= 0; FD_CLR(wrfd,&writefds); } @@ -59,6 +67,7 @@ void wrbufcore_afterselect(int rdfd, int wrfd) { r= read(rdfd,rp,min(buffersize-1-used,buf+buffersize-rp)); if (!r) { seeneof=1; writing=1; + wrbuf_report("seeneof"); } else if (r<0) { if (!(errno == EAGAIN || errno == EINTR)) { perror("read"); exit(1); } } else { @@ -66,7 +75,10 @@ void wrbufcore_afterselect(int rdfd, int wrfd) { rp+= r; if (rp == buf+buffersize) rp=buf; } - if (used > waitfill) writing=1; + if (used > waitfill) { + if (!writing) wrbuf_report("starting"); + writing=1; + } } if (FD_ISSET(wrfd,&writefds) && used) {