diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-04-16 19:56:33 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-04-16 19:56:33 +0000 |
commit | 561177a1dd111f05aa3edc4d0b89bf1341627027 (patch) | |
tree | afff0dcfa999ed24e7b525f13761731c8090f859 /src | |
parent | bd0bf459793be5616a16f3c54fe93654a836b756 (diff) | |
download | luasocket-561177a1dd111f05aa3edc4d0b89bf1341627027.tar.gz luasocket-561177a1dd111f05aa3edc4d0b89bf1341627027.tar.bz2 luasocket-561177a1dd111f05aa3edc4d0b89bf1341627027.zip |
Some internal functions were not static.
Correct select bug that would crash on closed sockets.
Diffstat (limited to 'src')
-rw-r--r-- | src/luasocket.c | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/src/luasocket.c b/src/luasocket.c index 1f9780d..6512108 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
@@ -211,13 +211,13 @@ static char *socket_strerror(void); | |||
211 | static char *connect_strerror(void); | 211 | static char *connect_strerror(void); |
212 | 212 | ||
213 | /* socket auxiliary functions */ | 213 | /* socket auxiliary functions */ |
214 | const char *tcp_trybind(p_sock sock, const char *address, | 214 | static const char *tcp_trybind(p_sock sock, const char *address, |
215 | unsigned short port, int backlog); | 215 | unsigned short port, int backlog); |
216 | const char *tcp_tryconnect(p_sock sock, const char *address, | 216 | static const char *tcp_tryconnect(p_sock sock, const char *address, |
217 | unsigned short port); | 217 | unsigned short port); |
218 | const char *udp_setpeername(p_sock sock, const char *address, | 218 | static const char *udp_setpeername(p_sock sock, const char *address, |
219 | unsigned short port); | 219 | unsigned short port); |
220 | const char *udp_setsockname(p_sock sock, const char *address, | 220 | static const char *udp_setsockname(p_sock sock, const char *address, |
221 | unsigned short port); | 221 | unsigned short port); |
222 | static void set_reuseaddr(p_sock sock); | 222 | static void set_reuseaddr(p_sock sock); |
223 | static void set_blocking(p_sock sock); | 223 | static void set_blocking(p_sock sock); |
@@ -586,24 +586,27 @@ int global_select(lua_State *L) | |||
586 | if (!lua_isnil(L, 1)) { | 586 | if (!lua_isnil(L, 1)) { |
587 | lua_pushnil(L); | 587 | lua_pushnil(L); |
588 | while (lua_next(L, 1)) { | 588 | while (lua_next(L, 1)) { |
589 | if (lua_tag(L, -1) == tags->table) { | 589 | if (lua_tag(L, -1) == tags->table) { /* skip strange fields */ |
590 | p_sock sock = get_sock(L, -1, tags, NULL); | 590 | p_sock sock = get_sock(L, -1, tags, NULL); |
591 | lua_pushnumber(L, sock->sock); | 591 | if (sock->sock != INVALID_SOCKET) { /* skip closed sockets */ |
592 | lua_pushvalue(L, -2); | 592 | lua_pushnumber(L, sock->sock); |
593 | lua_settable(L, byfds); | 593 | lua_pushvalue(L, -2); |
594 | if (sock->sock > max) max = sock->sock; | 594 | lua_settable(L, byfds); |
595 | /* a socket can have unread data in our internal buffer. in | 595 | if (sock->sock > max) max = sock->sock; |
596 | * that case, we only call select to find out which of the | 596 | /* a socket can have unread data in our internal |
597 | * other sockets can be written to or read from immediately. */ | 597 | buffer. in that case, we only call select to find |
598 | if (!bf_isempty(sock)) { | 598 | out which of the other sockets can be written to |
599 | ms = 0; | 599 | or read from immediately. */ |
600 | lua_pushnumber(L, lua_getn(L, canread) + 1); | 600 | if (!bf_isempty(sock)) { |
601 | lua_pushvalue(L, -2); | 601 | ms = 0; |
602 | lua_settable(L, canread); | 602 | lua_pushnumber(L, lua_getn(L, canread) + 1); |
603 | } else { | 603 | lua_pushvalue(L, -2); |
604 | FD_SET(sock->sock, &readfds); | 604 | lua_settable(L, canread); |
605 | prfds = &readfds; | 605 | } else { |
606 | } | 606 | FD_SET(sock->sock, &readfds); |
607 | prfds = &readfds; | ||
608 | } | ||
609 | } | ||
607 | } | 610 | } |
608 | /* get rid of lua_next value and expose index */ | 611 | /* get rid of lua_next value and expose index */ |
609 | lua_pop(L, 1); | 612 | lua_pop(L, 1); |
@@ -613,14 +616,16 @@ int global_select(lua_State *L) | |||
613 | if (!lua_isnil(L, 2)) { | 616 | if (!lua_isnil(L, 2)) { |
614 | lua_pushnil(L); | 617 | lua_pushnil(L); |
615 | while (lua_next(L, 2)) { | 618 | while (lua_next(L, 2)) { |
616 | if (lua_tag(L, -1) == tags->table) { | 619 | if (lua_tag(L, -1) == tags->table) { /* skip strange fields */ |
617 | p_sock sock = get_sock(L, -1, tags, NULL); | 620 | p_sock sock = get_sock(L, -1, tags, NULL); |
618 | lua_pushnumber(L, sock->sock); | 621 | if (sock->sock != INVALID_SOCKET) { /* skip closed sockets */ |
619 | lua_pushvalue(L, -2); | 622 | lua_pushnumber(L, sock->sock); |
620 | lua_settable(L, byfds); | 623 | lua_pushvalue(L, -2); |
621 | if (sock->sock > max) max = sock->sock; | 624 | lua_settable(L, byfds); |
622 | FD_SET(sock->sock, &writefds); | 625 | if (sock->sock > max) max = sock->sock; |
623 | pwfds = &writefds; | 626 | FD_SET(sock->sock, &writefds); |
627 | pwfds = &writefds; | ||
628 | } | ||
624 | } | 629 | } |
625 | /* get rid of lua_next value and expose index */ | 630 | /* get rid of lua_next value and expose index */ |
626 | lua_pop(L, 1); | 631 | lua_pop(L, 1); |
@@ -995,7 +1000,7 @@ static void handle_sigpipe(void) | |||
995 | * Returns | 1000 | * Returns |
996 | * NULL in case of success, error message otherwise | 1001 | * NULL in case of success, error message otherwise |
997 | \*-------------------------------------------------------------------------*/ | 1002 | \*-------------------------------------------------------------------------*/ |
998 | const char *tcp_tryconnect(p_sock sock, const char *address, | 1003 | static const char *tcp_tryconnect(p_sock sock, const char *address, |
999 | unsigned short port) | 1004 | unsigned short port) |
1000 | { | 1005 | { |
1001 | struct sockaddr_in remote; | 1006 | struct sockaddr_in remote; |
@@ -1053,7 +1058,7 @@ void set_reuseaddr(p_sock sock) | |||
1053 | * Returns | 1058 | * Returns |
1054 | * NULL in case of success, error message otherwise | 1059 | * NULL in case of success, error message otherwise |
1055 | \*-------------------------------------------------------------------------*/ | 1060 | \*-------------------------------------------------------------------------*/ |
1056 | const char *tcp_trybind(p_sock sock, const char *address, | 1061 | static const char *tcp_trybind(p_sock sock, const char *address, |
1057 | unsigned short port, int backlog) | 1062 | unsigned short port, int backlog) |
1058 | { | 1063 | { |
1059 | struct sockaddr_in local; | 1064 | struct sockaddr_in local; |
@@ -1106,7 +1111,7 @@ const char *tcp_trybind(p_sock sock, const char *address, | |||
1106 | * Returns | 1111 | * Returns |
1107 | * NULL in case of success, error message otherwise | 1112 | * NULL in case of success, error message otherwise |
1108 | \*-------------------------------------------------------------------------*/ | 1113 | \*-------------------------------------------------------------------------*/ |
1109 | const char *udp_setsockname(p_sock sock, const char *address, | 1114 | static const char *udp_setsockname(p_sock sock, const char *address, |
1110 | unsigned short port) | 1115 | unsigned short port) |
1111 | { | 1116 | { |
1112 | struct sockaddr_in local; | 1117 | struct sockaddr_in local; |
@@ -1151,7 +1156,7 @@ const char *udp_setsockname(p_sock sock, const char *address, | |||
1151 | * Returns | 1156 | * Returns |
1152 | * NULL in case of success, error message otherwise | 1157 | * NULL in case of success, error message otherwise |
1153 | \*-------------------------------------------------------------------------*/ | 1158 | \*-------------------------------------------------------------------------*/ |
1154 | const char *udp_setpeername(p_sock sock, const char *address, | 1159 | static const char *udp_setpeername(p_sock sock, const char *address, |
1155 | unsigned short port) | 1160 | unsigned short port) |
1156 | { | 1161 | { |
1157 | struct sockaddr_in local; | 1162 | struct sockaddr_in local; |