it turns out you don't need -1/EGAIN to know edge triggering told you
there is no more data, it's enough to read/write less than you asked for
This commit is contained in:
parent
f3c0e69988
commit
d9cbb3940c
@ -20,7 +20,7 @@ int64 io_mmapwritefile(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callb
|
||||
const char* c;
|
||||
unsigned long left;
|
||||
#ifdef __MINGW32__
|
||||
if (!e->mh) e->mh=CreateFileMapping(out,0,PAGE_READONLY,0,0,NULL);
|
||||
if (!e->mh) e->mh=CreateFileMapping(in,0,PAGE_READONLY,0,0,NULL);
|
||||
if (!e->mh) goto readwrite;
|
||||
#endif
|
||||
do {
|
||||
@ -56,8 +56,7 @@ int64 io_mmapwritefile(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callb
|
||||
while (left>0) {
|
||||
m=writecb(out,c,left);
|
||||
if (m<0) {
|
||||
e->canwrite=0;
|
||||
e->next_write=-1;
|
||||
io_eagain(out);
|
||||
if (errno!=EAGAIN) {
|
||||
#ifdef __MINGW32__
|
||||
UnmapViewOfFile(e->mmapped);
|
||||
@ -75,6 +74,11 @@ int64 io_mmapwritefile(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callb
|
||||
bytes-=m;
|
||||
off+=m;
|
||||
c+=m;
|
||||
if (e && left>0) {
|
||||
e->canwrite=0;
|
||||
e->next_write=-1;
|
||||
return sent;
|
||||
}
|
||||
}
|
||||
} while (bytes);
|
||||
if (e->mmapped) {
|
||||
@ -109,6 +113,11 @@ readwrite:
|
||||
n-=m;
|
||||
bytes-=m;
|
||||
tmp+=m;
|
||||
if (e && m!=n) {
|
||||
e->canwrite=0;
|
||||
e->next_write=-1;
|
||||
goto abort;
|
||||
}
|
||||
}
|
||||
}
|
||||
abort:
|
||||
|
@ -14,8 +14,14 @@
|
||||
int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) {
|
||||
off_t sbytes;
|
||||
int r=sendfile(fd,s,off,n,0,&sbytes,0);
|
||||
if (r==-1)
|
||||
if (r==-1) {
|
||||
io_entry* e=iarray_get(&io_fds,s);
|
||||
if (e) {
|
||||
e->canwrite=0;
|
||||
e->next_write=-1;
|
||||
}
|
||||
return (errno==EAGAIN?(sbytes?sbytes:-1):-3);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -31,6 +37,13 @@ int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) {
|
||||
int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) {
|
||||
long long r=sendfile64(out,in,off,bytes,0,0);
|
||||
if (r==-1 && errno!=EAGAIN) r=-3;
|
||||
if (r!=bytes) {
|
||||
io_entry* e=iarray_get(&io_fds,s);
|
||||
if (e) {
|
||||
e->canwrite=0;
|
||||
e->next_write=-1;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -45,6 +58,13 @@ int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) {
|
||||
off64_t o=off;
|
||||
long long r=sendfile64(out,in,&o,bytes);
|
||||
if (r==-1 && errno!=EAGAIN) r=-3;
|
||||
if (r!=bytes) {
|
||||
io_entry* e=iarray_get(&io_fds,s);
|
||||
if (e) {
|
||||
e->canwrite=0;
|
||||
e->next_write=-1;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -65,9 +85,16 @@ int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) {
|
||||
p.file_bytes=bytes;
|
||||
p.trailer_data=0;
|
||||
p.trailer_length=0;
|
||||
if (send_file(&destfd,&p,0)>=0)
|
||||
if (send_file(&destfd,&p,0)>=0) {
|
||||
if (p.bytes_sent != bytes) {
|
||||
io_entry* e=iarray_get(&io_fds,s);
|
||||
if (e) {
|
||||
e->canwrite=0;
|
||||
e->next_write=-1;
|
||||
}
|
||||
}
|
||||
return p.bytes_sent;
|
||||
if (errno==EAGAIN)
|
||||
} if (errno==EAGAIN)
|
||||
return -1;
|
||||
else
|
||||
return -3;
|
||||
@ -99,15 +126,17 @@ int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) {
|
||||
n-=todo;
|
||||
if (n==0) return done;
|
||||
continue;
|
||||
} else if (i==-1) {
|
||||
} else {
|
||||
if (e) {
|
||||
e->canwrite=0;
|
||||
e->next_write=-1;
|
||||
}
|
||||
if (i==-1)
|
||||
return (errno==EAGAIN?-1:-3);
|
||||
} else
|
||||
else
|
||||
return done+i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -86,7 +86,7 @@ int64 io_tryread(int64 d,char* buf,int64 len) {
|
||||
if (!e) { errno=EBADF; return -3; }
|
||||
if (!e->nonblock) {
|
||||
p.fd=d;
|
||||
if (p.fd != d) { errno=EBADF; return -3; } /* catch overflow */
|
||||
if (p.fd!=d) { errno=EBADF; return -3; } /* catch integer truncation */
|
||||
p.events=POLLIN;
|
||||
switch (poll(&p,1,0)) {
|
||||
case -1: return -3;
|
||||
@ -110,7 +110,7 @@ int64 io_tryread(int64 d,char* buf,int64 len) {
|
||||
if (errno!=EAGAIN)
|
||||
r=-3;
|
||||
}
|
||||
if (r==-1 || r==0) {
|
||||
if (r!=len) {
|
||||
e->canread=0;
|
||||
#if defined(HAVE_SIGIO) || defined(HAVE_EPOLL)
|
||||
if (d==alt_firstread) {
|
||||
|
@ -104,7 +104,7 @@ int64 io_trywrite(int64 d,const char* buf,int64 len) {
|
||||
if (errno!=EAGAIN)
|
||||
r=-3;
|
||||
}
|
||||
if (r==-1 || r==0) {
|
||||
if (r!=len) {
|
||||
e->canwrite=0;
|
||||
#if defined(HAVE_SIGIO) || defined(HAVE_EPOLL)
|
||||
if (d==alt_firstwrite) {
|
||||
|
@ -125,8 +125,15 @@ int64 io_waituntil2(int64 milliseconds) {
|
||||
int n;
|
||||
struct epoll_event y[100];
|
||||
io_entry* e;
|
||||
if (alt_firstread>=0 && (e=iarray_get(&io_fds,alt_firstread)) && e->canread) return 1;
|
||||
if (alt_firstwrite>=0 && (e=iarray_get(&io_fds,alt_firstwrite)) && e->canwrite) return 1;
|
||||
if (alt_firstread>=0 && (e=iarray_get(&io_fds,alt_firstread)) && e->canread) {
|
||||
// write(1,"r",1);
|
||||
return 1;
|
||||
}
|
||||
if (alt_firstwrite>=0 && (e=iarray_get(&io_fds,alt_firstwrite)) && e->canwrite) {
|
||||
// write(1,"w",1);
|
||||
return 1;
|
||||
}
|
||||
// write(1,".",1);
|
||||
if ((n=epoll_wait(io_master,y,100,milliseconds))==-1) return -1;
|
||||
for (i=0; i<n; ++i) {
|
||||
e=iarray_get(&io_fds,y[i].data.fd);
|
||||
|
@ -237,6 +237,7 @@ eagain:
|
||||
goto abort;
|
||||
}
|
||||
}
|
||||
io_eagain(s);
|
||||
} else break;
|
||||
}
|
||||
abort:
|
||||
|
Loading…
x
Reference in New Issue
Block a user