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;
|
const char* c;
|
||||||
unsigned long left;
|
unsigned long left;
|
||||||
#ifdef __MINGW32__
|
#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;
|
if (!e->mh) goto readwrite;
|
||||||
#endif
|
#endif
|
||||||
do {
|
do {
|
||||||
@ -56,8 +56,7 @@ int64 io_mmapwritefile(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callb
|
|||||||
while (left>0) {
|
while (left>0) {
|
||||||
m=writecb(out,c,left);
|
m=writecb(out,c,left);
|
||||||
if (m<0) {
|
if (m<0) {
|
||||||
e->canwrite=0;
|
io_eagain(out);
|
||||||
e->next_write=-1;
|
|
||||||
if (errno!=EAGAIN) {
|
if (errno!=EAGAIN) {
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
UnmapViewOfFile(e->mmapped);
|
UnmapViewOfFile(e->mmapped);
|
||||||
@ -75,6 +74,11 @@ int64 io_mmapwritefile(int64 out,int64 in,uint64 off,uint64 bytes,io_write_callb
|
|||||||
bytes-=m;
|
bytes-=m;
|
||||||
off+=m;
|
off+=m;
|
||||||
c+=m;
|
c+=m;
|
||||||
|
if (e && left>0) {
|
||||||
|
e->canwrite=0;
|
||||||
|
e->next_write=-1;
|
||||||
|
return sent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (bytes);
|
} while (bytes);
|
||||||
if (e->mmapped) {
|
if (e->mmapped) {
|
||||||
@ -109,6 +113,11 @@ readwrite:
|
|||||||
n-=m;
|
n-=m;
|
||||||
bytes-=m;
|
bytes-=m;
|
||||||
tmp+=m;
|
tmp+=m;
|
||||||
|
if (e && m!=n) {
|
||||||
|
e->canwrite=0;
|
||||||
|
e->next_write=-1;
|
||||||
|
goto abort;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
abort:
|
abort:
|
||||||
|
@ -14,8 +14,14 @@
|
|||||||
int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) {
|
int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) {
|
||||||
off_t sbytes;
|
off_t sbytes;
|
||||||
int r=sendfile(fd,s,off,n,0,&sbytes,0);
|
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 (errno==EAGAIN?(sbytes?sbytes:-1):-3);
|
||||||
|
}
|
||||||
return n;
|
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) {
|
int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) {
|
||||||
long long r=sendfile64(out,in,off,bytes,0,0);
|
long long r=sendfile64(out,in,off,bytes,0,0);
|
||||||
if (r==-1 && errno!=EAGAIN) r=-3;
|
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;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +58,13 @@ int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) {
|
|||||||
off64_t o=off;
|
off64_t o=off;
|
||||||
long long r=sendfile64(out,in,&o,bytes);
|
long long r=sendfile64(out,in,&o,bytes);
|
||||||
if (r==-1 && errno!=EAGAIN) r=-3;
|
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;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,9 +85,16 @@ int64 io_sendfile(int64 out,int64 in,uint64 off,uint64 bytes) {
|
|||||||
p.file_bytes=bytes;
|
p.file_bytes=bytes;
|
||||||
p.trailer_data=0;
|
p.trailer_data=0;
|
||||||
p.trailer_length=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;
|
return p.bytes_sent;
|
||||||
if (errno==EAGAIN)
|
} if (errno==EAGAIN)
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
return -3;
|
return -3;
|
||||||
@ -99,14 +126,16 @@ int64 io_sendfile(int64 s,int64 fd,uint64 off,uint64 n) {
|
|||||||
n-=todo;
|
n-=todo;
|
||||||
if (n==0) return done;
|
if (n==0) return done;
|
||||||
continue;
|
continue;
|
||||||
} else if (i==-1) {
|
} else {
|
||||||
if (e) {
|
if (e) {
|
||||||
e->canwrite=0;
|
e->canwrite=0;
|
||||||
e->next_write=-1;
|
e->next_write=-1;
|
||||||
}
|
}
|
||||||
return (errno==EAGAIN?-1:-3);
|
if (i==-1)
|
||||||
} else
|
return (errno==EAGAIN?-1:-3);
|
||||||
return done+i;
|
else
|
||||||
|
return done+i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ int64 io_tryread(int64 d,char* buf,int64 len) {
|
|||||||
if (!e) { errno=EBADF; return -3; }
|
if (!e) { errno=EBADF; return -3; }
|
||||||
if (!e->nonblock) {
|
if (!e->nonblock) {
|
||||||
p.fd=d;
|
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;
|
p.events=POLLIN;
|
||||||
switch (poll(&p,1,0)) {
|
switch (poll(&p,1,0)) {
|
||||||
case -1: return -3;
|
case -1: return -3;
|
||||||
@ -110,7 +110,7 @@ int64 io_tryread(int64 d,char* buf,int64 len) {
|
|||||||
if (errno!=EAGAIN)
|
if (errno!=EAGAIN)
|
||||||
r=-3;
|
r=-3;
|
||||||
}
|
}
|
||||||
if (r==-1 || r==0) {
|
if (r!=len) {
|
||||||
e->canread=0;
|
e->canread=0;
|
||||||
#if defined(HAVE_SIGIO) || defined(HAVE_EPOLL)
|
#if defined(HAVE_SIGIO) || defined(HAVE_EPOLL)
|
||||||
if (d==alt_firstread) {
|
if (d==alt_firstread) {
|
||||||
|
@ -104,7 +104,7 @@ int64 io_trywrite(int64 d,const char* buf,int64 len) {
|
|||||||
if (errno!=EAGAIN)
|
if (errno!=EAGAIN)
|
||||||
r=-3;
|
r=-3;
|
||||||
}
|
}
|
||||||
if (r==-1 || r==0) {
|
if (r!=len) {
|
||||||
e->canwrite=0;
|
e->canwrite=0;
|
||||||
#if defined(HAVE_SIGIO) || defined(HAVE_EPOLL)
|
#if defined(HAVE_SIGIO) || defined(HAVE_EPOLL)
|
||||||
if (d==alt_firstwrite) {
|
if (d==alt_firstwrite) {
|
||||||
|
@ -125,8 +125,15 @@ int64 io_waituntil2(int64 milliseconds) {
|
|||||||
int n;
|
int n;
|
||||||
struct epoll_event y[100];
|
struct epoll_event y[100];
|
||||||
io_entry* e;
|
io_entry* e;
|
||||||
if (alt_firstread>=0 && (e=iarray_get(&io_fds,alt_firstread)) && e->canread) return 1;
|
if (alt_firstread>=0 && (e=iarray_get(&io_fds,alt_firstread)) && e->canread) {
|
||||||
if (alt_firstwrite>=0 && (e=iarray_get(&io_fds,alt_firstwrite)) && e->canwrite) return 1;
|
// 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;
|
if ((n=epoll_wait(io_master,y,100,milliseconds))==-1) return -1;
|
||||||
for (i=0; i<n; ++i) {
|
for (i=0; i<n; ++i) {
|
||||||
e=iarray_get(&io_fds,y[i].data.fd);
|
e=iarray_get(&io_fds,y[i].data.fd);
|
||||||
|
@ -237,6 +237,7 @@ eagain:
|
|||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
io_eagain(s);
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
abort:
|
abort:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user