aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2005-03-11 02:21:27 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2005-03-11 02:21:27 +0000
commit6dc9c1096a664fe3642e774aadcb5af9f511176e (patch)
tree66a688e9854d801e594687fac6565da833952bbf
parente57f9e9964ac16b1fd09028ea533457f3029d296 (diff)
downloadluasocket-6dc9c1096a664fe3642e774aadcb5af9f511176e.tar.gz
luasocket-6dc9c1096a664fe3642e774aadcb5af9f511176e.tar.bz2
luasocket-6dc9c1096a664fe3642e774aadcb5af9f511176e.zip
Seems to be working on windows.
-rw-r--r--samples/forward.lua7
-rw-r--r--src/buffer.c2
-rw-r--r--src/tcp.c8
-rw-r--r--src/timeout.h2
-rw-r--r--src/wsocket.c3
5 files changed, 12 insertions, 10 deletions
diff --git a/samples/forward.lua b/samples/forward.lua
index 46f51c8..fe0d20a 100644
--- a/samples/forward.lua
+++ b/samples/forward.lua
@@ -57,7 +57,7 @@ function init()
57 assert(iport, "invalid arguments") 57 assert(iport, "invalid arguments")
58 -- create our server socket 58 -- create our server socket
59 local server = assert(socket.bind("*", iport)) 59 local server = assert(socket.bind("*", iport))
60 server:settimeout(0.1) -- we don't want to be killed by bad luck 60 server:settimeout(0) -- we don't want to be killed by bad luck
61 -- make sure server is tested for readability 61 -- make sure server is tested for readability
62 receiving:insert(server) 62 receiving:insert(server)
63 -- add server context 63 -- add server context
@@ -71,7 +71,7 @@ end
71 71
72-- starts a connection in a non-blocking way 72-- starts a connection in a non-blocking way
73function connect(who, host, port) 73function connect(who, host, port)
74 who:settimeout(0.1) 74 who:settimeout(0)
75print("trying to connect peer", who, host, port) 75print("trying to connect peer", who, host, port)
76 local ret, err = who:connect(host, port) 76 local ret, err = who:connect(host, port)
77 if not ret and err == "timeout" then 77 if not ret and err == "timeout" then
@@ -89,12 +89,11 @@ print("connection failed", who)
89 end 89 end
90end 90end
91 91
92-- gets rid of a client and its peer 92-- gets rid of a client
93function kick(who) 93function kick(who)
94 if who and context[who] then 94 if who and context[who] then
95 sending:remove(who) 95 sending:remove(who)
96 receiving:remove(who) 96 receiving:remove(who)
97 local peer = context[who].peer
98 context[who] = nil 97 context[who] = nil
99 who:close() 98 who:close()
100 end 99 end
diff --git a/src/buffer.c b/src/buffer.c
index 45cd0f2..62211d8 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -77,7 +77,7 @@ int buf_meth_send(lua_State *L, p_buf buf) {
77 int top = lua_gettop(L); 77 int top = lua_gettop(L);
78 p_tm tm = tm_markstart(buf->tm); 78 p_tm tm = tm_markstart(buf->tm);
79 int err = IO_DONE; 79 int err = IO_DONE;
80 size_t size, sent; 80 size_t size = 0, sent = 0;
81 const char *data = luaL_checklstring(L, 2, &size); 81 const char *data = luaL_checklstring(L, 2, &size);
82 long start = (long) luaL_optnumber(L, 3, 1); 82 long start = (long) luaL_optnumber(L, 3, 1);
83 long end = (long) luaL_optnumber(L, 4, -1); 83 long end = (long) luaL_optnumber(L, 4, -1);
diff --git a/src/tcp.c b/src/tcp.c
index 7ff3054..3aa1538 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -228,10 +228,12 @@ static int meth_connect(lua_State *L)
228 228
229static int meth_connected(lua_State *L) 229static int meth_connected(lua_State *L)
230{ 230{
231 p_tcp tcp; 231 p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1);
232 int err; 232 int err;
233 tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1); 233 t_tm tm;
234 err = sock_connected(&tcp->sock, &tcp->tm); 234 tm_init(&tm, 0.1, -1);
235 tm_markstart(&tm);
236 err = sock_connected(&tcp->sock, &tm);
235 if (err != IO_DONE) { 237 if (err != IO_DONE) {
236 lua_pushnil(L); 238 lua_pushnil(L);
237 lua_pushstring(L, sock_strerror(err)); 239 lua_pushstring(L, sock_strerror(err));
diff --git a/src/timeout.h b/src/timeout.h
index 595aac2..d2f9be0 100644
--- a/src/timeout.h
+++ b/src/timeout.h
@@ -10,8 +10,8 @@
10 10
11/* timeout control structure */ 11/* timeout control structure */
12typedef struct t_tm_ { 12typedef struct t_tm_ {
13 double total; /* total number of miliseconds for operation */
14 double block; /* maximum time for blocking calls */ 13 double block; /* maximum time for blocking calls */
14 double total; /* total number of miliseconds for operation */
15 double start; /* time of start of operation */ 15 double start; /* time of start of operation */
16} t_tm; 16} t_tm;
17typedef t_tm *p_tm; 17typedef t_tm *p_tm;
diff --git a/src/wsocket.c b/src/wsocket.c
index 8b00fa5..2c30fbb 100644
--- a/src/wsocket.c
+++ b/src/wsocket.c
@@ -129,10 +129,11 @@ int sock_connect(p_sock ps, SA *addr, socklen_t len, p_tm tm) {
129\*-------------------------------------------------------------------------*/ 129\*-------------------------------------------------------------------------*/
130int sock_connected(p_sock ps, p_tm tm) { 130int sock_connected(p_sock ps, p_tm tm) {
131 int err; 131 int err;
132 /* give windows time to find out what is up (yes, disgusting) */
132 if ((err = sock_waitfd(ps, WAITFD_C, tm)) == IO_CLOSED) { 133 if ((err = sock_waitfd(ps, WAITFD_C, tm)) == IO_CLOSED) {
133 int len = sizeof(err); 134 int len = sizeof(err);
134 /* give windows time to set the error (yes, disgusting) */ 135 /* give windows time to set the error (yes, disgusting) */
135 Sleep(0); 136 Sleep(10);
136 /* find out why we failed */ 137 /* find out why we failed */
137 getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &len); 138 getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &len);
138 /* we KNOW there was an error. if 'why' is 0, we will return 139 /* we KNOW there was an error. if 'why' is 0, we will return