From 39e7ee90bb9ad9bcceb7cef7af38e76e86dbe458 Mon Sep 17 00:00:00 2001 From: leitner Date: Thu, 5 Jun 2014 20:43:01 +0000 Subject: [PATCH] introduce io_eagain_read and io_eagain_write (discontinue using io_eagain plz) --- CHANGES | 1 + io.h | 6 ++++-- io/io_eagain_read.c | 15 +++++++++++++++ io/io_eagain_write.c | 15 +++++++++++++++ io/iob_send.c | 6 +++--- test/httpd.c | 4 ++-- 6 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 io/io_eagain_read.c create mode 100644 io/io_eagain_write.c diff --git a/CHANGES b/CHANGES index c91ff1c..677edd7 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ SECURITY: check for integer overflow in stralloc_ready switch io_fds from array to newly implemented (hopefully thread-safe) iarray switch epoll from level triggering to edge triggering + introduce io_eagain_read and io_eagain_write (discontinue using io_eagain plz) 0.29: save 8 bytes in taia.h for 64-bit systems diff --git a/io.h b/io.h index 0a20a37..a39f185 100644 --- a/io.h +++ b/io.h @@ -64,8 +64,10 @@ int64 io_waituntil2(int64 milliseconds); void io_check(); /* signal that read/accept/whatever returned EAGAIN */ -/* needed for SIGIO */ -void io_eagain(int64 d); +/* needed for SIGIO and epoll */ +void io_eagain(int64 d); /* do not use, API was a bad idea */ +void io_eagain_read(int64 d); /* use these ones */ +void io_eagain_write(int64 d); /* return next descriptor from io_wait that can be read from */ int64 io_canread(); diff --git a/io/io_eagain_read.c b/io/io_eagain_read.c new file mode 100644 index 0000000..71f89a4 --- /dev/null +++ b/io/io_eagain_read.c @@ -0,0 +1,15 @@ +#include "io_internal.h" + +void io_eagain_read(int64 d) { + io_entry* e=iarray_get(&io_fds,d); + if (e) { + e->canread=0; +#if defined(HAVE_SIGIO) || defined(HAVE_EPOLL) + if (d==alt_firstread) { + debug_printf(("io_eagain: dequeueing %lld from alt read queue (next is %ld)\n",d,e->next_read)); + alt_firstread=e->next_read; + } +#endif + e->next_read=-1; + } +} diff --git a/io/io_eagain_write.c b/io/io_eagain_write.c new file mode 100644 index 0000000..f8c1bae --- /dev/null +++ b/io/io_eagain_write.c @@ -0,0 +1,15 @@ +#include "io_internal.h" + +void io_eagain_write(int64 d) { + io_entry* e=iarray_get(&io_fds,d); + if (e) { + e->canwrite=0; +#if defined(HAVE_SIGIO) || defined(HAVE_EPOLL) + if (d==alt_firstwrite) { + debug_printf(("io_eagain: dequeueing %lld from alt write queue (next is %ld)\n",d,e->next_write)); + alt_firstwrite=e->next_write; + } +#endif + e->next_write=-1; + } +} diff --git a/io/iob_send.c b/io/iob_send.c index 8f7fe7b..4ccbe92 100644 --- a/io/iob_send.c +++ b/io/iob_send.c @@ -182,7 +182,7 @@ int64 iob_send(int64 s,io_batch* b) { sent=-3; else { eagain: - io_eagain(s); + io_eagain_write(s); return -1; } } @@ -201,7 +201,7 @@ eagain: sent=writev(s,v,headers); if (sent==-1) { if (errno==EAGAIN) { - io_eagain(s); + io_eagain_write(s); return -1; } sent=-3; @@ -237,7 +237,7 @@ eagain: goto abort; } } - io_eagain(s); + io_eagain_write(s); } else break; } abort: diff --git a/test/httpd.c b/test/httpd.c index 13e5f7d..6c0a142 100644 --- a/test/httpd.c +++ b/test/httpd.c @@ -235,7 +235,7 @@ int main() { buffer_putnlflush(buffer_2); } if (errno==EAGAIN) - io_eagain(s); + io_eagain_read(s); else carp("socket_accept6"); } else { @@ -285,7 +285,7 @@ emerge: struct http_data* h=io_getcookie(i); int64 r=iob_send(i,&h->iob); /* printf("iob_send returned %lld\n",r); */ - if (r==-1) io_eagain(i); else + if (r==-1) io_eagain_write(i); else if (r<=0) { array_trunc(&h->r); iob_reset(&h->iob);