some more eagain handling in tryread and trywrite

cosmetic change
master
leitner 8 years ago
parent 26a193bff0
commit c29096b2e0

@ -105,6 +105,8 @@ int64 io_tryread(int64 d,char* buf,int64 len) {
if (!e->nonblock) { if (!e->nonblock) {
setitimer(ITIMER_REAL,&old,0); setitimer(ITIMER_REAL,&old,0);
} }
if (r==-1 && errno==EAGAIN)
io_eagain_read(d);
if (r==-1) { if (r==-1) {
if (errno==EINTR) errno=EAGAIN; if (errno==EINTR) errno=EAGAIN;
if (errno!=EAGAIN) if (errno!=EAGAIN)
@ -112,13 +114,13 @@ int64 io_tryread(int64 d,char* buf,int64 len) {
} }
if (r!=len) { if (r!=len) {
e->canread=0; e->canread=0;
io_eagain_read(d);
#if defined(HAVE_SIGIO) #if defined(HAVE_SIGIO)
#if 0 #if 0
debug_printf(("io_tryread: dequeueing %ld from alt read queue (next is %ld)\n",d,alt_firstread)); debug_printf(("io_tryread: dequeueing %ld from alt read queue (next is %ld)\n",d,alt_firstread));
alt_firstread=e->next_read; alt_firstread=e->next_read;
e->next_read=-1; e->next_read=-1;
#else #else
if (d==alt_curread) alt_curread=-1;
} else { } else {
debug_printf(("io_tryread: enqueueing %ld into alt read queue (next is %ld)\n",d,alt_firstread)); debug_printf(("io_tryread: enqueueing %ld into alt read queue (next is %ld)\n",d,alt_firstread));
e->next_read=alt_firstread; e->next_read=alt_firstread;

@ -99,6 +99,8 @@ int64 io_trywrite(int64 d,const char* buf,int64 len) {
if (!e->nonblock) { if (!e->nonblock) {
setitimer(ITIMER_REAL,&old,0); setitimer(ITIMER_REAL,&old,0);
} }
if (r==-1 && errno==EAGAIN)
io_eagain_write(d);
if (r==-1) { if (r==-1) {
if (errno==EINTR) errno=EAGAIN; if (errno==EINTR) errno=EAGAIN;
if (errno!=EAGAIN) if (errno!=EAGAIN)
@ -106,6 +108,7 @@ int64 io_trywrite(int64 d,const char* buf,int64 len) {
} }
if (r!=len) { if (r!=len) {
e->canwrite=0; e->canwrite=0;
io_eagain_write(d);
#if defined(HAVE_SIGIO) #if defined(HAVE_SIGIO)
if (d==alt_firstwrite) { if (d==alt_firstwrite) {
#if 0 #if 0
@ -113,11 +116,11 @@ int64 io_trywrite(int64 d,const char* buf,int64 len) {
alt_firstwrite=e->next_write; alt_firstwrite=e->next_write;
e->next_write=-1; e->next_write=-1;
#else #else
if (d==alt_curwrite) alt_curwrite=-1; if (d==alt_curwrite) alt_curwrite=-1;
} else { } else {
debug_printf(("io_trywrite: enqueueing %ld into alt write queue (next is %ld)\n",d,alt_firstwrite)); debug_printf(("io_trywrite: enqueueing %ld into alt write queue (next is %ld)\n",d,alt_firstwrite));
e->next_write=alt_firstwrite; e->next_write=alt_firstwrite;
alt_firstwrite=d; alt_firstwrite=d;
#endif #endif
} }
#endif #endif

19
t.c

@ -35,7 +35,7 @@
// #define atomic_add(mem,val) asm volatile ("lock; add%z0 %1, %0": "+m" (mem): "ir" (val)) // #define atomic_add(mem,val) asm volatile ("lock; add%z0 %1, %0": "+m" (mem): "ir" (val))
static int64 writecb(int64 fd,const void* buf,uint64 n) { int64 writecb(int64 fd,const void* buf,uint64 n) {
(void)fd; (void)fd;
(void)buf; (void)buf;
(void)n; (void)n;
@ -49,13 +49,13 @@ static int64 writecb(int64 fd,const void* buf,uint64 n) {
return -1; return -1;
} }
static int ret0(const char* s,void* foo) { int ret0(const char* s,void* foo) {
(void)foo; (void)foo;
assert(strcmp(s,"fnord")==0); assert(strcmp(s,"fnord")==0);
return 0; return 0;
} }
static int ret1(const char* s,void* foo) { int ret1(const char* s,void* foo) {
static int i; static int i;
(void)foo; (void)foo;
switch (i) { switch (i) {
@ -68,7 +68,20 @@ static int ret1(const char* s,void* foo) {
} }
int main(int argc,char* argv[]) { int main(int argc,char* argv[]) {
(void)argc;
(void)argv;
#if 1
char buf[1024];
size_t n;
scan_base64("eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9",buf,&n);
write(1,buf,n); write(1,"\n",1);
scan_base64("eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ",buf,&n);
write(1,buf,n); write(1,"\n",1);
#endif
#if 0
int s=socket_udp6(); int s=socket_udp6();
#endif
#if 0 #if 0
char buf[100]; char buf[100];
assert(fmt_varint(buf,1)==1 && buf[0]==1); assert(fmt_varint(buf,1)==1 && buf[0]==1);

Loading…
Cancel
Save