You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
806 B
45 lines
806 B
|
|
#include <unistd.h> |
|
#include <errno.h> |
|
|
|
/* -1: not now (try later), -2: con closed, -3: unexpected error */ |
|
|
|
int iobase_write(int fd, const void* buf, int len) { |
|
int res = write(fd, buf, len); |
|
if (res >= 0) return res; |
|
switch (errno) { |
|
case EAGAIN: |
|
#if EAGAIN != EWOULDBLOCK |
|
case EWOULDBLOCK: |
|
#endif |
|
case EINTR: |
|
return -1; |
|
break; |
|
case ECONNRESET: |
|
case EPIPE: |
|
case ETIMEDOUT: |
|
return -2; |
|
default: |
|
return -3; |
|
} |
|
} |
|
|
|
/* 0: eof, -1: not now (try later), -2: con closed, -3: unexpected error */ |
|
int iobase_read(int fd, void* buf, int len) { |
|
int res = read(fd, buf, len); |
|
if (res >= 0) return res; |
|
switch (errno) { |
|
case EAGAIN: |
|
#if EAGAIN != EWOULDBLOCK |
|
case EWOULDBLOCK: |
|
#endif |
|
case EINTR: |
|
return -1; |
|
break; |
|
case ECONNRESET: |
|
case ETIMEDOUT: |
|
return -2; |
|
default: |
|
return -3; |
|
} |
|
}
|
|
|