fiber io: incorrect used SET_READABLE

This commit is contained in:
zsxxsz 2018-01-16 23:46:42 +08:00
parent a2b795a7fe
commit e3a50c370d
2 changed files with 38 additions and 23 deletions

View File

@ -201,7 +201,7 @@ ssize_t acl_fiber_read(socket_t fd, void *buf, size_t count)
ssize_t ret; ssize_t ret;
int err; int err;
if (SET_READABLE(fe)) { if (IS_READABLE(fe)) {
CLR_READABLE(fe); CLR_READABLE(fe);
} else { } else {
fiber_wait_read(fe); fiber_wait_read(fe);
@ -250,7 +250,7 @@ ssize_t acl_fiber_readv(socket_t fd, const struct iovec *iov, int iovcnt)
ssize_t ret; ssize_t ret;
int err; int err;
if (SET_READABLE(fe)) { if (IS_READABLE(fe)) {
CLR_READABLE(fe); CLR_READABLE(fe);
} else { } else {
fiber_wait_read(fe); fiber_wait_read(fe);
@ -304,7 +304,7 @@ ssize_t __stdcall acl_fiber_recv(socket_t sockfd, void *buf, size_t len, int fla
ssize_t ret; ssize_t ret;
int err; int err;
if (SET_READABLE(fe)) { if (IS_READABLE(fe)) {
CLR_READABLE(fe); CLR_READABLE(fe);
} else { } else {
fiber_wait_read(fe); fiber_wait_read(fe);
@ -360,7 +360,7 @@ ssize_t __stdcall acl_fiber_recvfrom(socket_t sockfd, void *buf, size_t len,
ssize_t ret; ssize_t ret;
int err; int err;
if (SET_READABLE(fe)) { if (IS_READABLE(fe)) {
CLR_READABLE(fe); CLR_READABLE(fe);
} else { } else {
fiber_wait_read(fe); fiber_wait_read(fe);
@ -412,7 +412,7 @@ ssize_t acl_fiber_recvmsg(socket_t sockfd, struct msghdr *msg, int flags)
ssize_t ret; ssize_t ret;
int err; int err;
if (SET_READABLE(fe)) { if (IS_READABLE(fe)) {
CLR_READABLE(fe); CLR_READABLE(fe);
} else { } else {
fiber_wait_read(fe); fiber_wait_read(fe);

View File

@ -100,6 +100,12 @@ int acl_fiber_listen(socket_t sockfd, int backlog)
return -1; return -1;
} }
#if FIBER_EAGAIN == FIBER_EWOULDBLOCK
# define error_again(x) ((x) == FIBER_EAGAIN)
#else
# define error_again(x) ((x) == FIBER_EAGAIN || (x) == FIBER_EWOULDBLOCK)
#endif
//#define FAST_ACCEPT //#define FAST_ACCEPT
socket_t __stdcall acl_fiber_accept(socket_t sockfd, struct sockaddr *addr, socket_t __stdcall acl_fiber_accept(socket_t sockfd, struct sockaddr *addr,
@ -107,9 +113,7 @@ socket_t __stdcall acl_fiber_accept(socket_t sockfd, struct sockaddr *addr,
{ {
FILE_EVENT *fe; FILE_EVENT *fe;
socket_t clifd; socket_t clifd;
#ifdef FAST_ACCEPT
int err; int err;
#endif
if (sockfd == INVALID_SOCKET) { if (sockfd == INVALID_SOCKET) {
msg_error("%s: invalid sockfd %d", __FUNCTION__, sockfd); msg_error("%s: invalid sockfd %d", __FUNCTION__, sockfd);
@ -167,24 +171,35 @@ socket_t __stdcall acl_fiber_accept(socket_t sockfd, struct sockaddr *addr,
return clifd; return clifd;
#else #else
fe = fiber_file_open(sockfd); fe = fiber_file_open(sockfd);
fiber_wait_read(fe);
if (acl_fiber_killed(fe->fiber)) { while(1) {
msg_info("%s(%d), %s: fiber-%u was killed", __FILE__, if (IS_READABLE(fe)) {
__LINE__, __FUNCTION__, acl_fiber_id(fe->fiber)); CLR_READABLE(fe);
return -1; } else {
fiber_wait_read(fe);
}
clifd = __sys_accept(sockfd, addr, addrlen);
if (clifd != INVALID_SOCKET) {
non_blocking(clifd, NON_BLOCKING);
tcp_nodelay(clifd, 1);
return clifd;
}
err = acl_fiber_last_error();
fiber_save_errno(err);
if (acl_fiber_killed(fe->fiber)) {
msg_info("%s(%d), %s: fiber-%u was killed", __FILE__,
__LINE__, __FUNCTION__, acl_fiber_id(fe->fiber));
return -1;
}
if (!error_again(err)) {
return clifd;
}
} }
clifd = __sys_accept(sockfd, addr, addrlen);
if (clifd != INVALID_SOCKET) {
non_blocking(clifd, NON_BLOCKING);
tcp_nodelay(clifd, 1);
return clifd;
}
fiber_save_errno(acl_fiber_last_error());
return clifd;
#endif #endif
} }