mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 11:57:43 +08:00
fiber io: incorrect used SET_READABLE
This commit is contained in:
parent
a2b795a7fe
commit
e3a50c370d
@ -201,7 +201,7 @@ ssize_t acl_fiber_read(socket_t fd, void *buf, size_t count)
|
||||
ssize_t ret;
|
||||
int err;
|
||||
|
||||
if (SET_READABLE(fe)) {
|
||||
if (IS_READABLE(fe)) {
|
||||
CLR_READABLE(fe);
|
||||
} else {
|
||||
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;
|
||||
int err;
|
||||
|
||||
if (SET_READABLE(fe)) {
|
||||
if (IS_READABLE(fe)) {
|
||||
CLR_READABLE(fe);
|
||||
} else {
|
||||
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;
|
||||
int err;
|
||||
|
||||
if (SET_READABLE(fe)) {
|
||||
if (IS_READABLE(fe)) {
|
||||
CLR_READABLE(fe);
|
||||
} else {
|
||||
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;
|
||||
int err;
|
||||
|
||||
if (SET_READABLE(fe)) {
|
||||
if (IS_READABLE(fe)) {
|
||||
CLR_READABLE(fe);
|
||||
} else {
|
||||
fiber_wait_read(fe);
|
||||
@ -412,7 +412,7 @@ ssize_t acl_fiber_recvmsg(socket_t sockfd, struct msghdr *msg, int flags)
|
||||
ssize_t ret;
|
||||
int err;
|
||||
|
||||
if (SET_READABLE(fe)) {
|
||||
if (IS_READABLE(fe)) {
|
||||
CLR_READABLE(fe);
|
||||
} else {
|
||||
fiber_wait_read(fe);
|
||||
|
@ -100,6 +100,12 @@ int acl_fiber_listen(socket_t sockfd, int backlog)
|
||||
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
|
||||
|
||||
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;
|
||||
socket_t clifd;
|
||||
#ifdef FAST_ACCEPT
|
||||
int err;
|
||||
#endif
|
||||
|
||||
if (sockfd == INVALID_SOCKET) {
|
||||
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;
|
||||
#else
|
||||
fe = fiber_file_open(sockfd);
|
||||
fiber_wait_read(fe);
|
||||
|
||||
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;
|
||||
while(1) {
|
||||
if (IS_READABLE(fe)) {
|
||||
CLR_READABLE(fe);
|
||||
} 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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user