From cf4d923d70992c152917cf6100753ebf0eac89d6 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 21 Mar 2003 01:07:23 +0000 Subject: Ported to Win32! --- src/luasocket.c | 2 +- src/timeout.c | 4 ++-- src/unix.c | 10 ++++------ src/unix.h | 39 ++++----------------------------------- 4 files changed, 11 insertions(+), 44 deletions(-) (limited to 'src') 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 @@ \*-------------------------------------------------------------------------*/ LUASOCKET_API int lua_socketlibopen(lua_State *L) { + compat_open(L); priv_open(L); select_open(L); base_open(L); tm_open(L); - compat_open(L); fd_open(L); sock_open(L); 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) { double n = luaL_checknumber(L, 1); #ifdef WIN32 - Sleep(n*1000); + Sleep((int)n*1000); #else - sleep(n); + sleep((int)n); #endif return 0; } diff --git a/src/unix.c b/src/unix.c index 0fc08bd..511a6bb 100644 --- a/src/unix.c +++ b/src/unix.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Network compatibilization module \*=========================================================================*/ -#include - #include #include @@ -17,14 +15,14 @@ static cchar *try_setbooloption(lua_State *L, COMPAT_FD sock, int name); /*=========================================================================*\ * Exported functions. \*=========================================================================*/ -void compat_open(lua_State *L) +int compat_open(lua_State *L) { - /* Instals a handler to ignore sigpipe. This function is not - needed on the WinSock2, since it's sockets don't raise signals. */ + /* Instals a handler to ignore sigpipe. */ struct sigaction new; memset(&new, 0, sizeof(new)); new.sa_handler = SIG_IGN; sigaction(SIGPIPE, &new, NULL); + return 1; } 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, err = PRIV_CLOSED; #ifdef __CYGWIN__ /* this is for CYGWIN, which is like Unix but has Win32 bugs */ - if (sent < 0 && errno == EWOULDBLOCK) err = PRIV_DONE; + if (errno == EWOULDBLOCK) err = PRIV_DONE; #endif *sent = 0; } else { diff --git a/src/unix.h b/src/unix.h index 944b471..5f89569 100644 --- a/src/unix.h +++ b/src/unix.h @@ -1,7 +1,5 @@ -#ifndef COMPAT_H_ -#define COMPAT_H_ - -#include "lspriv.h" +#ifndef UNIX_H_ +#define UNIX_H_ /*=========================================================================*\ * BSD include files @@ -24,46 +22,17 @@ #include /* sigpipe handling */ #include - +/* IP stuff*/ #include #include #define COMPAT_FD int #define COMPAT_INVALIDFD (-1) -/* we are lazy... */ -typedef struct sockaddr SA; - -/*=========================================================================*\ -* Exported functions -\*=========================================================================*/ -void compat_open(lua_State *L); - #define compat_bind bind #define compat_connect connect #define compat_listen listen #define compat_close close #define compat_select select -COMPAT_FD compat_socket(int domain, int type, int protocol); -COMPAT_FD compat_accept(COMPAT_FD s, SA *addr, int *len, int deadline); -int compat_send(COMPAT_FD c, cchar *data, size_t count, size_t *done, - int deadline); -int compat_recv(COMPAT_FD c, uchar *data, size_t count, size_t *done, - int deadline); -int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *done, - int deadline, SA *addr, int len); -int compat_recvfrom(COMPAT_FD c, uchar *data, size_t count, size_t *got, - int deadline, SA *addr, int *len); -void compat_setnonblocking(COMPAT_FD sock); -void compat_setblocking(COMPAT_FD sock); -void compat_setreuseaddr(COMPAT_FD sock); - -const char *compat_hoststrerror(void); -const char *compat_socketstrerror(void); -const char *compat_bindstrerror(void); -const char *compat_connectstrerror(void); - -cchar *compat_trysetoptions(lua_State *L, COMPAT_FD sock); - -#endif /* COMPAT_H_ */ +#endif /* UNIX_H_ */ -- cgit v1.2.3-55-g6feb