Skip to content

Commit

Permalink
bugfix in lib_acl: POLLHUP | POLLERR should not be set as input param…
Browse files Browse the repository at this point in the history
…eters.
  • Loading branch information
zhengshuxin committed Feb 3, 2018
1 parent 342f42c commit 6d9add2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 26 deletions.
4 changes: 4 additions & 0 deletions lib_acl/changes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
�޸���ʷ�б���

------------------------------------------------------------------------
623) 2018.2.3
623.1) bugfix: acl_read_wait.c/acl_write_wait.c ���� poll API ʱ��
POLLHUP | POLLERR ��Ӧ��Ϊ�������

622) 2018.1.30
622.1) event: Ϊ������� core �ļ�̫�󽫴���ռ�������ڵ��¼����汨��ʱ���� core��
���Ǽ�¼������־����� exit(1) �˳�����
Expand Down
3 changes: 2 additions & 1 deletion lib_acl/src/stdlib/iostuff/acl_peekfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int acl_peekfd(ACL_SOCKET fd)
#ifdef ACL_UNIX
return (ioctl(fd, FIONREAD, (char *) &count) < 0 ? -1 : count);
#elif defined(ACL_WINDOWS)
return (ioctlsocket(fd, FIONREAD, (unsigned long *) &count) < 0 ? -1 : count);
return (ioctlsocket(fd, FIONREAD, (unsigned long *) &count) < 0
? -1 : count);
#endif
}
30 changes: 20 additions & 10 deletions lib_acl/src/stdlib/iostuff/acl_read_wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,26 @@ static acl_poll_fn __sys_poll = WSAPoll;
static acl_poll_fn __sys_poll = poll;
# endif

void acl_set_poll(acl_poll_fn fn)
/* xxx: defined in acl_write_wait.c */
extern void set_poll4write(acl_poll_fn fn);

static void set_poll4read(acl_poll_fn fn)
{
__sys_poll = fn;
}

void acl_set_poll(acl_poll_fn fn)
{
set_poll4read(fn);
}

int acl_read_poll_wait(ACL_SOCKET fd, int delay)
{
const char *myname = "acl_read_poll_wait";
struct pollfd fds;
time_t begin;

fds.events = POLLIN | POLLHUP | POLLERR;
fds.events = POLLIN;
fds.fd = fd;

acl_set_error(0);
Expand All @@ -273,7 +281,11 @@ int acl_read_poll_wait(ACL_SOCKET fd, int delay)
time(&begin);

switch (__sys_poll(&fds, 1, delay)) {
#ifdef ACL_WINDOWS
case SOCKET_ERROR:
#else
case -1:
#endif
if (acl_last_error() == ACL_EINTR)
continue;

Expand All @@ -293,21 +305,19 @@ int acl_read_poll_wait(ACL_SOCKET fd, int delay)
default:
if ((fds.revents & POLLIN))
return 0;
else if (fds.revents & (POLLHUP | POLLERR)) {
acl_msg_warn("%s(%d), %s: poll error: %s, "
"fd: %d, delay: %d, spent: %ld",
__FILE__, __LINE__, myname,
acl_last_serror(), fd, delay,
(long) (time(NULL) - begin));
return -1;
} else {
if (fds.revents & (POLLHUP | POLLERR | POLLNVAL)) {
acl_msg_warn("%s(%d), %s: poll error: %s, "
"fd: %d, delay: %d, spent: %ld",
__FILE__, __LINE__, myname,
acl_last_serror(), fd, delay,
(long) (time(NULL) - begin));
return -1;
}
acl_msg_warn("%s(%d), %s: poll error: %s, fd: %d, "
"delay: %d, spent: %ld", __FILE__, __LINE__,
myname, acl_last_serror(), fd, delay,
(long) (time(NULL) - begin));
return -1;
}
}
}
Expand Down
33 changes: 21 additions & 12 deletions lib_acl/src/stdlib/iostuff/acl_write_wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,37 @@
#include "stdlib/acl_iostuff.h"
#include "../../init/init.h"

#ifdef ACL_UNIX
#if defined(ACL_HAS_POLL)

# if defined(ACL_WINDOWS)
static acl_poll_fn __sys_poll = WSAPoll;
# else
static acl_poll_fn __sys_poll = poll;
# endif

extern void set_poll4write(acl_poll_fn fn);

void set_poll4write(acl_poll_fn fn)
{
__sys_poll = fn;
}

int acl_write_wait(ACL_SOCKET fd, int timeout)
{
const char *myname = "acl_write_wait";
struct pollfd fds;
int delay = timeout * 1000;

fds.events = POLLOUT | POLLHUP | POLLERR;
fds.events = POLLOUT /* | POLLHUP | POLLERR; */;
fds.fd = fd;

#if 0
acl_set_error(0);
#endif

for (;;) {
switch (poll(&fds, 1, delay)) {
switch (__sys_poll(&fds, 1, delay)) {
#ifdef ACL_WINDOWS
case SOCKET_ERROR:
#else
case -1:
#endif
if (acl_last_error() == ACL_EINTR)
continue;
acl_msg_error("%s(%d), %s: poll error(%s), fd: %d",
Expand All @@ -51,7 +64,7 @@ int acl_write_wait(ACL_SOCKET fd, int timeout)
acl_set_error(ACL_ETIMEDOUT);
return -1;
default:
if ((fds.revents & (POLLHUP | POLLERR))) {
if ((fds.revents & (POLLHUP | POLLERR | POLLNVAL))) {
/*
acl_msg_error("%s(%d), %s: fd: %d,"
"POLLHUP: %s, POLLERR: %s",
Expand Down Expand Up @@ -110,10 +123,6 @@ int acl_write_wait(ACL_SOCKET fd, int timeout)
} else
tp = 0;

#if 0
acl_set_error(0);
#endif

for (;;) {
#ifdef ACL_WINDOWS
switch (select(1, (fd_set *) 0, &wfds, &xfds, tp)) {
Expand Down
9 changes: 7 additions & 2 deletions lib_acl_cpp/samples/redis/redis/redis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ static void usage(const char* procname)
{
printf("usage: %s -h[help]\r\n"
"-s redis_addr[127.0.0.1:6379]\r\n"
"-p password[default: \"\"]\r\n"
"-n count\r\n"
"-C connect_timeout[default: 10]\r\n"
"-T rw_timeout[default: 10]\r\n"
Expand All @@ -170,9 +171,9 @@ static void usage(const char* procname)
int main(int argc, char* argv[])
{
int ch, n = 1, conn_timeout = 10, rw_timeout = 10;
acl::string addr("127.0.0.1:6379"), command;
acl::string addr("127.0.0.1:6379"), command, passwd;

while ((ch = getopt(argc, argv, "hs:n:C:T:a:")) > 0)
while ((ch = getopt(argc, argv, "hs:n:C:T:a:p:")) > 0)
{
switch (ch)
{
Expand All @@ -194,6 +195,9 @@ int main(int argc, char* argv[])
case 'a':
command = optarg;
break;
case 'p':
passwd = optarg;
break;
default:
break;
}
Expand All @@ -202,6 +206,7 @@ int main(int argc, char* argv[])
acl::acl_cpp_init();
acl::log::stdout_open(true);
acl::redis_client client(addr.c_str(), conn_timeout, rw_timeout);
client.set_password(passwd);
acl::redis cmd(&client);

bool ret;
Expand Down
6 changes: 5 additions & 1 deletion lib_fiber/c/src/event/event_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ static int poll_wait(EVENT *ev, int timeout)
}
#endif
n = __sys_poll(ep->pfds, ep->count, timeout);
if (n < 0) {
#ifdef SYS_WIN
if (n == SOCKET_ERROR) {
#else
if (n == -1) {
#endif
if (errno == EINTR) {
return 0;
}
Expand Down

0 comments on commit 6d9add2

Please sign in to comment.