aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c2
-rw-r--r--src/tcp.c8
-rw-r--r--src/timeout.h2
-rw-r--r--src/wsocket.c3
4 files changed, 9 insertions, 6 deletions
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