X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=cprogs%2Fwrbufcore.c;h=65fc2bede367227631169004b5e2598b84aa44fc;hp=417cb01ac0cef44f7cc03c80f04f0120152fc857;hb=925487e1be73d42c3ae6cf6c460cc3ee97612276;hpb=e483a046db5ff0972702a0dc29ba4e00b698d997 diff --git a/cprogs/wrbufcore.c b/cprogs/wrbufcore.c index 417cb01..65fc2be 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 @@ -22,27 +22,35 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public - * License along with this file; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * License along with this file; if not, consult the Free Software + * Foundation's website at www.fsf.org, or the GNU Project website at + * www.gnu.org. * */ #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 +68,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 +76,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) {