Ported to Win32!

This commit is contained in:
Diego Nehab 2003-03-21 01:07:23 +00:00
parent d3d4156ef9
commit cf4d923d70
7 changed files with 55 additions and 45 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -1,8 +1,6 @@
/*=========================================================================*\
* Network compatibilization module
\*=========================================================================*/
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
@ -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 {

View file

@ -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 <netdb.h>
/* sigpipe handling */
#include <signal.h>
/* IP stuff*/
#include <netinet/in.h>
#include <arpa/inet.h>
#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_ */