diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-21 01:07:23 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-21 01:07:23 +0000 |
| commit | cf4d923d70992c152917cf6100753ebf0eac89d6 (patch) | |
| tree | f1f21d4cfb193318af0d620c51ee8b8d41440035 /src | |
| parent | d3d4156ef9d4d7e934e246dc265138be224f2612 (diff) | |
| download | luasocket-cf4d923d70992c152917cf6100753ebf0eac89d6.tar.gz luasocket-cf4d923d70992c152917cf6100753ebf0eac89d6.tar.bz2 luasocket-cf4d923d70992c152917cf6100753ebf0eac89d6.zip | |
Ported to Win32!
Diffstat (limited to 'src')
| -rw-r--r-- | src/luasocket.c | 2 | ||||
| -rw-r--r-- | src/timeout.c | 4 | ||||
| -rw-r--r-- | src/unix.c | 10 | ||||
| -rw-r--r-- | src/unix.h | 39 |
4 files changed, 11 insertions, 44 deletions
diff --git a/src/luasocket.c b/src/luasocket.c index 26bc014..f6d1df7 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
| @@ -44,11 +44,11 @@ | |||
| 44 | \*-------------------------------------------------------------------------*/ | 44 | \*-------------------------------------------------------------------------*/ |
| 45 | LUASOCKET_API int lua_socketlibopen(lua_State *L) | 45 | LUASOCKET_API int lua_socketlibopen(lua_State *L) |
| 46 | { | 46 | { |
| 47 | compat_open(L); | ||
| 47 | priv_open(L); | 48 | priv_open(L); |
| 48 | select_open(L); | 49 | select_open(L); |
| 49 | base_open(L); | 50 | base_open(L); |
| 50 | tm_open(L); | 51 | tm_open(L); |
| 51 | compat_open(L); | ||
| 52 | fd_open(L); | 52 | fd_open(L); |
| 53 | sock_open(L); | 53 | sock_open(L); |
| 54 | inet_open(L); | 54 | inet_open(L); |
diff --git a/src/timeout.c b/src/timeout.c index dfece82..50a84da 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
| @@ -151,9 +151,9 @@ int tm_lua_sleep(lua_State *L) | |||
| 151 | { | 151 | { |
| 152 | double n = luaL_checknumber(L, 1); | 152 | double n = luaL_checknumber(L, 1); |
| 153 | #ifdef WIN32 | 153 | #ifdef WIN32 |
| 154 | Sleep(n*1000); | 154 | Sleep((int)n*1000); |
| 155 | #else | 155 | #else |
| 156 | sleep(n); | 156 | sleep((int)n); |
| 157 | #endif | 157 | #endif |
| 158 | return 0; | 158 | return 0; |
| 159 | } | 159 | } |
| @@ -1,8 +1,6 @@ | |||
| 1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
| 2 | * Network compatibilization module | 2 | * Network compatibilization module |
| 3 | \*=========================================================================*/ | 3 | \*=========================================================================*/ |
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | #include <lua.h> | 4 | #include <lua.h> |
| 7 | #include <lauxlib.h> | 5 | #include <lauxlib.h> |
| 8 | 6 | ||
| @@ -17,14 +15,14 @@ static cchar *try_setbooloption(lua_State *L, COMPAT_FD sock, int name); | |||
| 17 | /*=========================================================================*\ | 15 | /*=========================================================================*\ |
| 18 | * Exported functions. | 16 | * Exported functions. |
| 19 | \*=========================================================================*/ | 17 | \*=========================================================================*/ |
| 20 | void compat_open(lua_State *L) | 18 | int compat_open(lua_State *L) |
| 21 | { | 19 | { |
| 22 | /* Instals a handler to ignore sigpipe. This function is not | 20 | /* Instals a handler to ignore sigpipe. */ |
| 23 | needed on the WinSock2, since it's sockets don't raise signals. */ | ||
| 24 | struct sigaction new; | 21 | struct sigaction new; |
| 25 | memset(&new, 0, sizeof(new)); | 22 | memset(&new, 0, sizeof(new)); |
| 26 | new.sa_handler = SIG_IGN; | 23 | new.sa_handler = SIG_IGN; |
| 27 | sigaction(SIGPIPE, &new, NULL); | 24 | sigaction(SIGPIPE, &new, NULL); |
| 25 | return 1; | ||
| 28 | } | 26 | } |
| 29 | 27 | ||
| 30 | COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr, | 28 | COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr, |
| @@ -59,7 +57,7 @@ int compat_send(COMPAT_FD c, cchar *data, size_t count, size_t *sent, | |||
| 59 | err = PRIV_CLOSED; | 57 | err = PRIV_CLOSED; |
| 60 | #ifdef __CYGWIN__ | 58 | #ifdef __CYGWIN__ |
| 61 | /* this is for CYGWIN, which is like Unix but has Win32 bugs */ | 59 | /* this is for CYGWIN, which is like Unix but has Win32 bugs */ |
| 62 | if (sent < 0 && errno == EWOULDBLOCK) err = PRIV_DONE; | 60 | if (errno == EWOULDBLOCK) err = PRIV_DONE; |
| 63 | #endif | 61 | #endif |
| 64 | *sent = 0; | 62 | *sent = 0; |
| 65 | } else { | 63 | } else { |
| @@ -1,7 +1,5 @@ | |||
| 1 | #ifndef COMPAT_H_ | 1 | #ifndef UNIX_H_ |
| 2 | #define COMPAT_H_ | 2 | #define UNIX_H_ |
| 3 | |||
| 4 | #include "lspriv.h" | ||
| 5 | 3 | ||
| 6 | /*=========================================================================*\ | 4 | /*=========================================================================*\ |
| 7 | * BSD include files | 5 | * BSD include files |
| @@ -24,46 +22,17 @@ | |||
| 24 | #include <netdb.h> | 22 | #include <netdb.h> |
| 25 | /* sigpipe handling */ | 23 | /* sigpipe handling */ |
| 26 | #include <signal.h> | 24 | #include <signal.h> |
| 27 | 25 | /* IP stuff*/ | |
| 28 | #include <netinet/in.h> | 26 | #include <netinet/in.h> |
| 29 | #include <arpa/inet.h> | 27 | #include <arpa/inet.h> |
| 30 | 28 | ||
| 31 | #define COMPAT_FD int | 29 | #define COMPAT_FD int |
| 32 | #define COMPAT_INVALIDFD (-1) | 30 | #define COMPAT_INVALIDFD (-1) |
| 33 | 31 | ||
| 34 | /* we are lazy... */ | ||
| 35 | typedef struct sockaddr SA; | ||
| 36 | |||
| 37 | /*=========================================================================*\ | ||
| 38 | * Exported functions | ||
| 39 | \*=========================================================================*/ | ||
| 40 | void compat_open(lua_State *L); | ||
| 41 | |||
| 42 | #define compat_bind bind | 32 | #define compat_bind bind |
| 43 | #define compat_connect connect | 33 | #define compat_connect connect |
| 44 | #define compat_listen listen | 34 | #define compat_listen listen |
| 45 | #define compat_close close | 35 | #define compat_close close |
| 46 | #define compat_select select | 36 | #define compat_select select |
| 47 | 37 | ||
| 48 | COMPAT_FD compat_socket(int domain, int type, int protocol); | 38 | #endif /* UNIX_H_ */ |
| 49 | COMPAT_FD compat_accept(COMPAT_FD s, SA *addr, int *len, int deadline); | ||
| 50 | int compat_send(COMPAT_FD c, cchar *data, size_t count, size_t *done, | ||
| 51 | int deadline); | ||
| 52 | int compat_recv(COMPAT_FD c, uchar *data, size_t count, size_t *done, | ||
| 53 | int deadline); | ||
| 54 | int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *done, | ||
| 55 | int deadline, SA *addr, int len); | ||
| 56 | int compat_recvfrom(COMPAT_FD c, uchar *data, size_t count, size_t *got, | ||
| 57 | int deadline, SA *addr, int *len); | ||
| 58 | void compat_setnonblocking(COMPAT_FD sock); | ||
| 59 | void compat_setblocking(COMPAT_FD sock); | ||
| 60 | void compat_setreuseaddr(COMPAT_FD sock); | ||
| 61 | |||
| 62 | const char *compat_hoststrerror(void); | ||
| 63 | const char *compat_socketstrerror(void); | ||
| 64 | const char *compat_bindstrerror(void); | ||
| 65 | const char *compat_connectstrerror(void); | ||
| 66 | |||
| 67 | cchar *compat_trysetoptions(lua_State *L, COMPAT_FD sock); | ||
| 68 | |||
| 69 | #endif /* COMPAT_H_ */ | ||
