diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-09-12 22:07:08 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-09-12 22:07:08 +0000 |
| commit | d794e581ff769953d4f34ae44ecd14ac200f4991 (patch) | |
| tree | 70eb6ceede45330de447781368c5a3bdd16ed816 /src | |
| parent | b2df4282a37381438c46d4d8dbc520c1bf8ae7b1 (diff) | |
| download | luasocket-d794e581ff769953d4f34ae44ecd14ac200f4991.tar.gz luasocket-d794e581ff769953d4f34ae44ecd14ac200f4991.tar.bz2 luasocket-d794e581ff769953d4f34ae44ecd14ac200f4991.zip | |
lua_socketlibopen now returns a result code.
Diffstat (limited to 'src')
| -rw-r--r-- | src/luasocket.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/luasocket.c b/src/luasocket.c index 3b3f697..bbf7ca7 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
| @@ -8,12 +8,14 @@ | |||
| 8 | * This module is part of an effort to make the most important features | 8 | * This module is part of an effort to make the most important features |
| 9 | * of the IPv4 Socket layer available to Lua scripts. | 9 | * of the IPv4 Socket layer available to Lua scripts. |
| 10 | * The Lua interface to TCP/IP follows the BSD TCP/IP API closely, | 10 | * The Lua interface to TCP/IP follows the BSD TCP/IP API closely, |
| 11 | * trying to simplify all tasks involved in setting up a client connection | 11 | * trying to simplify all tasks involved in setting up both client |
| 12 | * and server connections. | 12 | * and server connections. |
| 13 | * The provided IO routines, send and receive, follow the Lua style, being | 13 | * The provided IO routines, send and receive, follow the Lua style, being |
| 14 | * very similar to the standard Lua read and write functions. | 14 | * very similar to the standard Lua read and write functions. |
| 15 | * The module implements both a BSD bind and a Winsock2 bind, and has | 15 | * The module implements both a BSD bind and a Winsock2 bind, and has |
| 16 | * been tested on several Unix flavors, as well as Windows 98 and NT. | 16 | * been tested on several Unix flavors, as well as Windows 98 and NT. |
| 17 | * | ||
| 18 | * RCS ID: $Id$ | ||
| 17 | \*=========================================================================*/ | 19 | \*=========================================================================*/ |
| 18 | 20 | ||
| 19 | /*=========================================================================*\ | 21 | /*=========================================================================*\ |
| @@ -1660,7 +1662,7 @@ static int receive_word(lua_State *L, p_sock sock) | |||
| 1660 | * Initializes the library interface with Lua and the socket library. | 1662 | * Initializes the library interface with Lua and the socket library. |
| 1661 | * Defines the symbols exported to Lua. | 1663 | * Defines the symbols exported to Lua. |
| 1662 | \*-------------------------------------------------------------------------*/ | 1664 | \*-------------------------------------------------------------------------*/ |
| 1663 | LUASOCKET_API void lua_socketlibopen(lua_State *L) | 1665 | LUASOCKET_API int lua_socketlibopen(lua_State *L) |
| 1664 | { | 1666 | { |
| 1665 | struct luaL_reg funcs[] = { | 1667 | struct luaL_reg funcs[] = { |
| 1666 | {"bind", global_tcpbind}, | 1668 | {"bind", global_tcpbind}, |
| @@ -1674,6 +1676,8 @@ LUASOCKET_API void lua_socketlibopen(lua_State *L) | |||
| 1674 | /* declare new Lua tags for used userdata values */ | 1676 | /* declare new Lua tags for used userdata values */ |
| 1675 | p_tags tags = (p_tags) lua_newuserdata(L, sizeof(t_tags)); | 1677 | p_tags tags = (p_tags) lua_newuserdata(L, sizeof(t_tags)); |
| 1676 | if (!tags) lua_error(L, "out of memory"); | 1678 | if (!tags) lua_error(L, "out of memory"); |
| 1679 | /* remove tags userdatum from stack but avoid garbage collection */ | ||
| 1680 | lua_ref(L, 1); | ||
| 1677 | tags->client = lua_newtag(L); | 1681 | tags->client = lua_newtag(L); |
| 1678 | tags->server = lua_newtag(L); | 1682 | tags->server = lua_newtag(L); |
| 1679 | tags->table = lua_newtag(L); | 1683 | tags->table = lua_newtag(L); |
| @@ -1690,7 +1694,7 @@ LUASOCKET_API void lua_socketlibopen(lua_State *L) | |||
| 1690 | lua_settagmethod(L, tags->table, "gc"); | 1694 | lua_settagmethod(L, tags->table, "gc"); |
| 1691 | #ifdef WIN32 | 1695 | #ifdef WIN32 |
| 1692 | /* WinSock needs special initialization */ | 1696 | /* WinSock needs special initialization */ |
| 1693 | winsock_open(); | 1697 | if (!winsock_open()) return 0; |
| 1694 | #else | 1698 | #else |
| 1695 | /* avoid getting killed by a SIGPIPE signal thrown by send */ | 1699 | /* avoid getting killed by a SIGPIPE signal thrown by send */ |
| 1696 | handle_sigpipe(); | 1700 | handle_sigpipe(); |
| @@ -1716,6 +1720,7 @@ LUASOCKET_API void lua_socketlibopen(lua_State *L) | |||
| 1716 | } | 1720 | } |
| 1717 | } | 1721 | } |
| 1718 | #endif | 1722 | #endif |
| 1723 | return 1; | ||
| 1719 | } | 1724 | } |
| 1720 | 1725 | ||
| 1721 | /*=========================================================================*\ | 1726 | /*=========================================================================*\ |
