mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 04:28:20 +01:00
Seems to be working on windows.
This commit is contained in:
parent
e57f9e9964
commit
6dc9c1096a
@ -57,7 +57,7 @@ function init()
|
||||
assert(iport, "invalid arguments")
|
||||
-- create our server socket
|
||||
local server = assert(socket.bind("*", iport))
|
||||
server:settimeout(0.1) -- we don't want to be killed by bad luck
|
||||
server:settimeout(0) -- we don't want to be killed by bad luck
|
||||
-- make sure server is tested for readability
|
||||
receiving:insert(server)
|
||||
-- add server context
|
||||
@ -71,7 +71,7 @@ end
|
||||
|
||||
-- starts a connection in a non-blocking way
|
||||
function connect(who, host, port)
|
||||
who:settimeout(0.1)
|
||||
who:settimeout(0)
|
||||
print("trying to connect peer", who, host, port)
|
||||
local ret, err = who:connect(host, port)
|
||||
if not ret and err == "timeout" then
|
||||
@ -89,12 +89,11 @@ print("connection failed", who)
|
||||
end
|
||||
end
|
||||
|
||||
-- gets rid of a client and its peer
|
||||
-- gets rid of a client
|
||||
function kick(who)
|
||||
if who and context[who] then
|
||||
sending:remove(who)
|
||||
receiving:remove(who)
|
||||
local peer = context[who].peer
|
||||
context[who] = nil
|
||||
who:close()
|
||||
end
|
||||
|
@ -77,7 +77,7 @@ int buf_meth_send(lua_State *L, p_buf buf) {
|
||||
int top = lua_gettop(L);
|
||||
p_tm tm = tm_markstart(buf->tm);
|
||||
int err = IO_DONE;
|
||||
size_t size, sent;
|
||||
size_t size = 0, sent = 0;
|
||||
const char *data = luaL_checklstring(L, 2, &size);
|
||||
long start = (long) luaL_optnumber(L, 3, 1);
|
||||
long end = (long) luaL_optnumber(L, 4, -1);
|
||||
|
@ -228,10 +228,12 @@ static int meth_connect(lua_State *L)
|
||||
|
||||
static int meth_connected(lua_State *L)
|
||||
{
|
||||
p_tcp tcp;
|
||||
p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1);
|
||||
int err;
|
||||
tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1);
|
||||
err = sock_connected(&tcp->sock, &tcp->tm);
|
||||
t_tm tm;
|
||||
tm_init(&tm, 0.1, -1);
|
||||
tm_markstart(&tm);
|
||||
err = sock_connected(&tcp->sock, &tm);
|
||||
if (err != IO_DONE) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, sock_strerror(err));
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
/* timeout control structure */
|
||||
typedef struct t_tm_ {
|
||||
double total; /* total number of miliseconds for operation */
|
||||
double block; /* maximum time for blocking calls */
|
||||
double total; /* total number of miliseconds for operation */
|
||||
double start; /* time of start of operation */
|
||||
} t_tm;
|
||||
typedef t_tm *p_tm;
|
||||
|
@ -129,10 +129,11 @@ int sock_connect(p_sock ps, SA *addr, socklen_t len, p_tm tm) {
|
||||
\*-------------------------------------------------------------------------*/
|
||||
int sock_connected(p_sock ps, p_tm tm) {
|
||||
int err;
|
||||
/* give windows time to find out what is up (yes, disgusting) */
|
||||
if ((err = sock_waitfd(ps, WAITFD_C, tm)) == IO_CLOSED) {
|
||||
int len = sizeof(err);
|
||||
/* give windows time to set the error (yes, disgusting) */
|
||||
Sleep(0);
|
||||
Sleep(10);
|
||||
/* find out why we failed */
|
||||
getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &len);
|
||||
/* we KNOW there was an error. if 'why' is 0, we will return
|
||||
|
Loading…
Reference in New Issue
Block a user