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

5
NEW Normal file
View File

@ -0,0 +1,5 @@
Socket structures are independent
UDPBUFFERSIZE is now internal
Better treatment of closed connections: test!!!
HTTP post now deals with 1xx codes
connect, bind etc only try first address returned by resolver

38
TODO Normal file
View File

@ -0,0 +1,38 @@
- Inicializaccao das classes pode falhar?
* Como mostrar um erro em lua_socketlibopen()...
* O location do "redirect" pode ser relativo ao servidor atual (não pode,
mas os servidores fazem merda...)
* - Ajeitar para Lua 4.1
- Padronizar os retornos de funccao
- Thread-safe
- proteger gethostby*.* com um mutex GLOBAL!
- proteger o atomizar o conjunto (timedout, receive), (timedout, send)
- Usar "require" nos módulos
- SSL
- Fazer compilar com g++
- usar lua_verror
- separar as classes em arquivos
- criar mais uma classe, a de stream, entre p_sock e p_client
- criar um internal include file ls.h
- impedir que voe quando chamar accept(udpsocket())
- trocar recv and send por read e write (ver se funciona)
- checar operações em closed sockets
- checar teste de writable socket com select
- trocar IPv4 para networking ou ipc
- checar todos os metodos
- checar options em UDP
- checar todas as globais
- checar os metodos virtuais
- checar garbage collection
- unix 92 bytes maximo no endereço, incluindo o zero
- unix 9216 maximo de datagram size
- retorno de send/receive em datagram sockets pode ser refused...
- adicionar um método sock:setoption???

View File

@ -44,11 +44,11 @@
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_API int lua_socketlibopen(lua_State *L) LUASOCKET_API int lua_socketlibopen(lua_State *L)
{ {
compat_open(L);
priv_open(L); priv_open(L);
select_open(L); select_open(L);
base_open(L); base_open(L);
tm_open(L); tm_open(L);
compat_open(L);
fd_open(L); fd_open(L);
sock_open(L); sock_open(L);
inet_open(L); inet_open(L);

View File

@ -151,9 +151,9 @@ int tm_lua_sleep(lua_State *L)
{ {
double n = luaL_checknumber(L, 1); double n = luaL_checknumber(L, 1);
#ifdef WIN32 #ifdef WIN32
Sleep(n*1000); Sleep((int)n*1000);
#else #else
sleep(n); sleep((int)n);
#endif #endif
return 0; return 0;
} }

View File

@ -1,8 +1,6 @@
/*=========================================================================*\ /*=========================================================================*\
* Network compatibilization module * Network compatibilization module
\*=========================================================================*/ \*=========================================================================*/
#include <string.h>
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
@ -17,14 +15,14 @@ static cchar *try_setbooloption(lua_State *L, COMPAT_FD sock, int name);
/*=========================================================================*\ /*=========================================================================*\
* Exported functions. * Exported functions.
\*=========================================================================*/ \*=========================================================================*/
void compat_open(lua_State *L) int compat_open(lua_State *L)
{ {
/* Instals a handler to ignore sigpipe. This function is not /* Instals a handler to ignore sigpipe. */
needed on the WinSock2, since it's sockets don't raise signals. */
struct sigaction new; struct sigaction new;
memset(&new, 0, sizeof(new)); memset(&new, 0, sizeof(new));
new.sa_handler = SIG_IGN; new.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &new, NULL); sigaction(SIGPIPE, &new, NULL);
return 1;
} }
COMPAT_FD compat_accept(COMPAT_FD s, struct sockaddr *addr, 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; err = PRIV_CLOSED;
#ifdef __CYGWIN__ #ifdef __CYGWIN__
/* this is for CYGWIN, which is like Unix but has Win32 bugs */ /* 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 #endif
*sent = 0; *sent = 0;
} else { } else {

View File

@ -1,7 +1,5 @@
#ifndef COMPAT_H_ #ifndef UNIX_H_
#define COMPAT_H_ #define UNIX_H_
#include "lspriv.h"
/*=========================================================================*\ /*=========================================================================*\
* BSD include files * BSD include files
@ -24,46 +22,17 @@
#include <netdb.h> #include <netdb.h>
/* sigpipe handling */ /* sigpipe handling */
#include <signal.h> #include <signal.h>
/* IP stuff*/
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#define COMPAT_FD int #define COMPAT_FD int
#define COMPAT_INVALIDFD (-1) #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_bind bind
#define compat_connect connect #define compat_connect connect
#define compat_listen listen #define compat_listen listen
#define compat_close close #define compat_close close
#define compat_select select #define compat_select select
COMPAT_FD compat_socket(int domain, int type, int protocol); #endif /* UNIX_H_ */
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_ */

View File

@ -13,7 +13,7 @@ function fail(...)
end end
function warn(...) function warn(...)
local s = format(unpack(arg)) local s = string.format(unpack(arg))
io.write("WARNING: ", s, "\n") io.write("WARNING: ", s, "\n")
end end