aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2003-03-21 01:07:23 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2003-03-21 01:07:23 +0000
commitcf4d923d70992c152917cf6100753ebf0eac89d6 (patch)
treef1f21d4cfb193318af0d620c51ee8b8d41440035 /src
parentd3d4156ef9d4d7e934e246dc265138be224f2612 (diff)
downloadluasocket-cf4d923d70992c152917cf6100753ebf0eac89d6.tar.gz
luasocket-cf4d923d70992c152917cf6100753ebf0eac89d6.tar.bz2
luasocket-cf4d923d70992c152917cf6100753ebf0eac89d6.zip
Ported to Win32!
Diffstat (limited to 'src')
-rw-r--r--src/luasocket.c2
-rw-r--r--src/timeout.c4
-rw-r--r--src/unix.c10
-rw-r--r--src/unix.h39
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\*-------------------------------------------------------------------------*/
45LUASOCKET_API int lua_socketlibopen(lua_State *L) 45LUASOCKET_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}
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 @@
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\*=========================================================================*/
20void compat_open(lua_State *L) 18int 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
30COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr, 28COMPAT_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 {
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 @@
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... */
35typedef struct sockaddr SA;
36
37/*=========================================================================*\
38* Exported functions
39\*=========================================================================*/
40void 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
48COMPAT_FD compat_socket(int domain, int type, int protocol); 38#endif /* UNIX_H_ */
49COMPAT_FD compat_accept(COMPAT_FD s, SA *addr, int *len, int deadline);
50int compat_send(COMPAT_FD c, cchar *data, size_t count, size_t *done,
51 int deadline);
52int compat_recv(COMPAT_FD c, uchar *data, size_t count, size_t *done,
53 int deadline);
54int compat_sendto(COMPAT_FD c, cchar *data, size_t count, size_t *done,
55 int deadline, SA *addr, int len);
56int compat_recvfrom(COMPAT_FD c, uchar *data, size_t count, size_t *got,
57 int deadline, SA *addr, int *len);
58void compat_setnonblocking(COMPAT_FD sock);
59void compat_setblocking(COMPAT_FD sock);
60void compat_setreuseaddr(COMPAT_FD sock);
61
62const char *compat_hoststrerror(void);
63const char *compat_socketstrerror(void);
64const char *compat_bindstrerror(void);
65const char *compat_connectstrerror(void);
66
67cchar *compat_trysetoptions(lua_State *L, COMPAT_FD sock);
68
69#endif /* COMPAT_H_ */