Browse Source

introduce io_eagain_read and io_eagain_write (discontinue using io_eagain plz)

master
Felix von Leitner 6 years ago
parent
commit
d8da202a8b
6 changed files with 40 additions and 7 deletions
  1. +1
    -0
      CHANGES
  2. +4
    -2
      io.h
  3. +15
    -0
      io/io_eagain_read.c
  4. +15
    -0
      io/io_eagain_write.c
  5. +3
    -3
      io/iob_send.c
  6. +2
    -2
      test/httpd.c

+ 1
- 0
CHANGES View File

@@ -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


+ 4
- 2
io.h View File

@@ -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();


+ 15
- 0
io/io_eagain_read.c View File

@@ -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;
}
}

+ 15
- 0
io/io_eagain_write.c View File

@@ -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;
}
}

+ 3
- 3
io/iob_send.c View File

@@ -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:


+ 2
- 2
test/httpd.c View File

@@ -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);


Loading…
Cancel
Save