瀏覽代碼

some more eagain handling in tryread and trywrite

cosmetic change
master
Felix von Leitner 3 年之前
父節點
當前提交
6dcb99f00e
共有 3 個文件被更改,包括 27 次插入9 次删除
  1. +3
    -1
      io/io_tryread.c
  2. +8
    -5
      io/io_trywrite.c
  3. +16
    -3
      t.c

+ 3
- 1
io/io_tryread.c 查看文件

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


+ 8
- 5
io/io_trywrite.c 查看文件

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


+ 16
- 3
t.c 查看文件

@@ -35,7 +35,7 @@

// #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)buf;
(void)n;
@@ -49,13 +49,13 @@ static int64 writecb(int64 fd,const void* buf,uint64 n) {
return -1;
}

static int ret0(const char* s,void* foo) {
int ret0(const char* s,void* foo) {
(void)foo;
assert(strcmp(s,"fnord")==0);
return 0;
}

static int ret1(const char* s,void* foo) {
int ret1(const char* s,void* foo) {
static int i;
(void)foo;
switch (i) {
@@ -68,7 +68,20 @@ static int ret1(const char* s,void* foo) {
}

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();
#endif
#if 0
char buf[100];
assert(fmt_varint(buf,1)==1 && buf[0]==1);


Loading…
取消
儲存