diff --git a/lib_acl/changes.txt b/lib_acl/changes.txt index 6b2a3982e..7bbbcfd14 100644 --- a/lib_acl/changes.txt +++ b/lib_acl/changes.txt @@ -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) 退出进程 diff --git a/lib_acl/src/stdlib/iostuff/acl_peekfd.c b/lib_acl/src/stdlib/iostuff/acl_peekfd.c index f326b8ab5..2185a9703 100644 --- a/lib_acl/src/stdlib/iostuff/acl_peekfd.c +++ b/lib_acl/src/stdlib/iostuff/acl_peekfd.c @@ -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 } diff --git a/lib_acl/src/stdlib/iostuff/acl_read_wait.c b/lib_acl/src/stdlib/iostuff/acl_read_wait.c index b732ff7d4..dbff0a3b4 100644 --- a/lib_acl/src/stdlib/iostuff/acl_read_wait.c +++ b/lib_acl/src/stdlib/iostuff/acl_read_wait.c @@ -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); @@ -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; @@ -293,14 +305,7 @@ 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, @@ -308,6 +313,11 @@ int acl_read_poll_wait(ACL_SOCKET fd, int 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; } } } diff --git a/lib_acl/src/stdlib/iostuff/acl_write_wait.c b/lib_acl/src/stdlib/iostuff/acl_write_wait.c index dd479e4d8..321d7ad20 100644 --- a/lib_acl/src/stdlib/iostuff/acl_write_wait.c +++ b/lib_acl/src/stdlib/iostuff/acl_write_wait.c @@ -23,7 +23,20 @@ #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) { @@ -31,16 +44,16 @@ int acl_write_wait(ACL_SOCKET fd, int timeout) 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", @@ -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", @@ -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)) { diff --git a/lib_acl_cpp/samples/redis/redis/redis.cpp b/lib_acl_cpp/samples/redis/redis/redis.cpp index 6b40ad609..09a7a024f 100644 --- a/lib_acl_cpp/samples/redis/redis/redis.cpp +++ b/lib_acl_cpp/samples/redis/redis/redis.cpp @@ -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" @@ -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) { @@ -194,6 +195,9 @@ int main(int argc, char* argv[]) case 'a': command = optarg; break; + case 'p': + passwd = optarg; + break; default: break; } @@ -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; diff --git a/lib_fiber/c/src/event/event_poll.c b/lib_fiber/c/src/event/event_poll.c index 4c0a3dc66..10a94ef3c 100644 --- a/lib_fiber/c/src/event/event_poll.c +++ b/lib_fiber/c/src/event/event_poll.c @@ -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; }