diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/auxiliar.h | 4 | ||||
-rw-r--r-- | src/buffer.c | 4 | ||||
-rw-r--r-- | src/buffer.h | 2 | ||||
-rw-r--r-- | src/except.c | 5 | ||||
-rw-r--r-- | src/except.h | 2 | ||||
-rw-r--r-- | src/inet.c | 4 | ||||
-rw-r--r-- | src/inet.h | 2 | ||||
-rw-r--r-- | src/io.c | 1 | ||||
-rw-r--r-- | src/io.h | 5 | ||||
-rw-r--r-- | src/luasocket.c | 10 | ||||
-rw-r--r-- | src/luasocket.h | 4 | ||||
-rw-r--r-- | src/makefile | 7 | ||||
-rw-r--r-- | src/mime.c | 11 | ||||
-rw-r--r-- | src/mime.h | 11 | ||||
-rw-r--r-- | src/options.c | 3 | ||||
-rw-r--r-- | src/options.h | 2 | ||||
-rw-r--r-- | src/select.c | 4 | ||||
-rw-r--r-- | src/socket.h | 1 | ||||
-rw-r--r-- | src/tcp.c | 4 | ||||
-rw-r--r-- | src/tcp.h | 2 | ||||
-rw-r--r-- | src/timeout.c | 4 | ||||
-rw-r--r-- | src/timeout.h | 2 | ||||
-rw-r--r-- | src/udp.c | 4 | ||||
-rw-r--r-- | src/udp.h | 2 | ||||
-rw-r--r-- | src/unix.c | 4 | ||||
-rw-r--r-- | src/unix.h | 2 | ||||
-rw-r--r-- | src/url.lua | 5 | ||||
-rw-r--r-- | src/usocket.c | 11 | ||||
-rw-r--r-- | src/wsocket.c | 16 |
29 files changed, 73 insertions, 65 deletions
diff --git a/src/auxiliar.h b/src/auxiliar.h index 70f4704..ff20b50 100644 --- a/src/auxiliar.h +++ b/src/auxiliar.h | |||
@@ -31,8 +31,8 @@ | |||
31 | * RCS ID: $Id$ | 31 | * RCS ID: $Id$ |
32 | \*=========================================================================*/ | 32 | \*=========================================================================*/ |
33 | 33 | ||
34 | #include <lua.h> | 34 | #include "lua.h" |
35 | #include <lauxlib.h> | 35 | #include "lauxlib.h" |
36 | 36 | ||
37 | int aux_open(lua_State *L); | 37 | int aux_open(lua_State *L); |
38 | void aux_newclass(lua_State *L, const char *classname, luaL_reg *func); | 38 | void aux_newclass(lua_State *L, const char *classname, luaL_reg *func); |
diff --git a/src/buffer.c b/src/buffer.c index 1188fda..b69a9b8 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
@@ -4,8 +4,8 @@ | |||
4 | * | 4 | * |
5 | * RCS ID: $Id$ | 5 | * RCS ID: $Id$ |
6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
7 | #include <lua.h> | 7 | #include "lua.h" |
8 | #include <lauxlib.h> | 8 | #include "lauxlib.h" |
9 | 9 | ||
10 | #include "buffer.h" | 10 | #include "buffer.h" |
11 | 11 | ||
diff --git a/src/buffer.h b/src/buffer.h index 8e5fb6c..f43e676 100644 --- a/src/buffer.h +++ b/src/buffer.h | |||
@@ -17,7 +17,7 @@ | |||
17 | * | 17 | * |
18 | * RCS ID: $Id$ | 18 | * RCS ID: $Id$ |
19 | \*=========================================================================*/ | 19 | \*=========================================================================*/ |
20 | #include <lua.h> | 20 | #include "lua.h" |
21 | 21 | ||
22 | #include "io.h" | 22 | #include "io.h" |
23 | #include "timeout.h" | 23 | #include "timeout.h" |
diff --git a/src/except.c b/src/except.c index dabaf19..fc4c038 100644 --- a/src/except.c +++ b/src/except.c | |||
@@ -5,8 +5,9 @@ | |||
5 | * RCS ID: $Id$ | 5 | * RCS ID: $Id$ |
6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <lua.h> | 8 | |
9 | #include <lauxlib.h> | 9 | #include "lua.h" |
10 | #include "lauxlib.h" | ||
10 | 11 | ||
11 | #include "except.h" | 12 | #include "except.h" |
12 | 13 | ||
diff --git a/src/except.h b/src/except.h index 2c57b27..03e417d 100644 --- a/src/except.h +++ b/src/except.h | |||
@@ -28,7 +28,7 @@ | |||
28 | * RCS ID: $Id$ | 28 | * RCS ID: $Id$ |
29 | \*=========================================================================*/ | 29 | \*=========================================================================*/ |
30 | 30 | ||
31 | #include <lua.h> | 31 | #include "lua.h" |
32 | 32 | ||
33 | int except_open(lua_State *L); | 33 | int except_open(lua_State *L); |
34 | 34 | ||
@@ -7,8 +7,8 @@ | |||
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <string.h> | 8 | #include <string.h> |
9 | 9 | ||
10 | #include <lua.h> | 10 | #include "lua.h" |
11 | #include <lauxlib.h> | 11 | #include "lauxlib.h" |
12 | 12 | ||
13 | #include "inet.h" | 13 | #include "inet.h" |
14 | 14 | ||
@@ -16,7 +16,7 @@ | |||
16 | * | 16 | * |
17 | * RCS ID: $Id$ | 17 | * RCS ID: $Id$ |
18 | \*=========================================================================*/ | 18 | \*=========================================================================*/ |
19 | #include <lua.h> | 19 | #include "lua.h" |
20 | #include "socket.h" | 20 | #include "socket.h" |
21 | #include "timeout.h" | 21 | #include "timeout.h" |
22 | 22 | ||
@@ -27,7 +27,6 @@ const char *io_strerror(int err) { | |||
27 | case IO_DONE: return NULL; | 27 | case IO_DONE: return NULL; |
28 | case IO_CLOSED: return "closed"; | 28 | case IO_CLOSED: return "closed"; |
29 | case IO_TIMEOUT: return "timeout"; | 29 | case IO_TIMEOUT: return "timeout"; |
30 | case IO_CLIPPED: return "clipped"; | ||
31 | default: return "unknown error"; | 30 | default: return "unknown error"; |
32 | } | 31 | } |
33 | } | 32 | } |
@@ -15,7 +15,7 @@ | |||
15 | * RCS ID: $Id$ | 15 | * RCS ID: $Id$ |
16 | \*=========================================================================*/ | 16 | \*=========================================================================*/ |
17 | #include <stdio.h> | 17 | #include <stdio.h> |
18 | #include <lua.h> | 18 | #include "lua.h" |
19 | 19 | ||
20 | #include "timeout.h" | 20 | #include "timeout.h" |
21 | 21 | ||
@@ -24,8 +24,7 @@ enum { | |||
24 | IO_DONE = 0, /* operation completed successfully */ | 24 | IO_DONE = 0, /* operation completed successfully */ |
25 | IO_TIMEOUT = -1, /* operation timed out */ | 25 | IO_TIMEOUT = -1, /* operation timed out */ |
26 | IO_CLOSED = -2, /* the connection has been closed */ | 26 | IO_CLOSED = -2, /* the connection has been closed */ |
27 | IO_CLIPPED = -3, /* maxium bytes count reached */ | 27 | IO_UNKNOWN = -3 |
28 | IO_UNKNOWN = -4 | ||
29 | }; | 28 | }; |
30 | 29 | ||
31 | /* interface to error message function */ | 30 | /* interface to error message function */ |
diff --git a/src/luasocket.c b/src/luasocket.c index 94ea05b..434b5b7 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
@@ -17,15 +17,17 @@ | |||
17 | /*=========================================================================*\ | 17 | /*=========================================================================*\ |
18 | * Standard include files | 18 | * Standard include files |
19 | \*=========================================================================*/ | 19 | \*=========================================================================*/ |
20 | #include <lua.h> | 20 | #include "lua.h" |
21 | #include <lauxlib.h> | 21 | #include "lauxlib.h" |
22 | |||
23 | #if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501) | ||
22 | #include "compat-5.1.h" | 24 | #include "compat-5.1.h" |
23 | #include "luasocket.h" | 25 | #endif |
24 | 26 | ||
25 | /*=========================================================================*\ | 27 | /*=========================================================================*\ |
26 | * LuaSocket includes | 28 | * LuaSocket includes |
27 | \*=========================================================================*/ | 29 | \*=========================================================================*/ |
28 | 30 | #include "luasocket.h" | |
29 | #include "auxiliar.h" | 31 | #include "auxiliar.h" |
30 | #include "except.h" | 32 | #include "except.h" |
31 | #include "timeout.h" | 33 | #include "timeout.h" |
diff --git a/src/luasocket.h b/src/luasocket.h index c7d09d8..0143fa7 100644 --- a/src/luasocket.h +++ b/src/luasocket.h | |||
@@ -8,10 +8,10 @@ | |||
8 | * | 8 | * |
9 | * RCS ID: $Id$ | 9 | * RCS ID: $Id$ |
10 | \*=========================================================================*/ | 10 | \*=========================================================================*/ |
11 | #include <lua.h> | 11 | #include "lua.h" |
12 | 12 | ||
13 | /*-------------------------------------------------------------------------*\ | 13 | /*-------------------------------------------------------------------------*\ |
14 | * Current luasocket version | 14 | * Current socket library version |
15 | \*-------------------------------------------------------------------------*/ | 15 | \*-------------------------------------------------------------------------*/ |
16 | #define LUASOCKET_VERSION "LuaSocket 2.0" | 16 | #define LUASOCKET_VERSION "LuaSocket 2.0" |
17 | #define LUASOCKET_COPYRIGHT "Copyright (C) 2004-2005 Diego Nehab" | 17 | #define LUASOCKET_COPYRIGHT "Copyright (C) 2004-2005 Diego Nehab" |
diff --git a/src/makefile b/src/makefile index 7ef18bf..9a97dd3 100644 --- a/src/makefile +++ b/src/makefile | |||
@@ -11,6 +11,7 @@ include ../config | |||
11 | # Modules belonging to socket-core | 11 | # Modules belonging to socket-core |
12 | # | 12 | # |
13 | SOCKET_OBJS:= \ | 13 | SOCKET_OBJS:= \ |
14 | $(COMPAT)/compat-5.1.o \ | ||
14 | luasocket.o \ | 15 | luasocket.o \ |
15 | timeout.o \ | 16 | timeout.o \ |
16 | buffer.o \ | 17 | buffer.o \ |
@@ -22,15 +23,15 @@ SOCKET_OBJS:= \ | |||
22 | udp.o \ | 23 | udp.o \ |
23 | except.o \ | 24 | except.o \ |
24 | select.o \ | 25 | select.o \ |
25 | $(COMPAT)/compat-5.1.o \ | ||
26 | usocket.o | 26 | usocket.o |
27 | 27 | ||
28 | #------ | 28 | #------ |
29 | # Modules belonging mime-core | 29 | # Modules belonging mime-core |
30 | # | 30 | # |
31 | MIME_OBJS:=\ | 31 | MIME_OBJS:=\ |
32 | mime.o \ | 32 | $(COMPAT)/compat-5.1.o \ |
33 | $(COMPAT)/compat-5.1.o | 33 | mime.o |
34 | |||
34 | 35 | ||
35 | #------ | 36 | #------ |
36 | # Modules belonging unix (local domain sockets) | 37 | # Modules belonging unix (local domain sockets) |
@@ -6,10 +6,13 @@ | |||
6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
7 | #include <string.h> | 7 | #include <string.h> |
8 | 8 | ||
9 | #include <lua.h> | 9 | #include "lua.h" |
10 | #include <lauxlib.h> | 10 | #include "lauxlib.h" |
11 | 11 | ||
12 | #if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501) | ||
12 | #include "compat-5.1.h" | 13 | #include "compat-5.1.h" |
14 | #endif | ||
15 | |||
13 | #include "mime.h" | 16 | #include "mime.h" |
14 | 17 | ||
15 | /*=========================================================================*\ | 18 | /*=========================================================================*\ |
@@ -81,6 +84,10 @@ static UC b64unbase[256]; | |||
81 | MIME_API int luaopen_mime_core(lua_State *L) | 84 | MIME_API int luaopen_mime_core(lua_State *L) |
82 | { | 85 | { |
83 | luaL_openlib(L, "mime", func, 0); | 86 | luaL_openlib(L, "mime", func, 0); |
87 | /* make version string available to scripts */ | ||
88 | lua_pushstring(L, "_VERSION"); | ||
89 | lua_pushstring(L, MIME_VERSION); | ||
90 | lua_rawset(L, -3); | ||
84 | /* initialize lookup tables */ | 91 | /* initialize lookup tables */ |
85 | qpsetup(qpclass, qpunbase); | 92 | qpsetup(qpclass, qpunbase); |
86 | b64setup(b64unbase); | 93 | b64setup(b64unbase); |
@@ -1,7 +1,7 @@ | |||
1 | #ifndef MIME_H | 1 | #ifndef MIME_H |
2 | #define MIME_H | 2 | #define MIME_H |
3 | /*=========================================================================*\ | 3 | /*=========================================================================*\ |
4 | * MIME support functions | 4 | * Core MIME support |
5 | * LuaSocket toolkit | 5 | * LuaSocket toolkit |
6 | * | 6 | * |
7 | * This module provides functions to implement transfer content encodings | 7 | * This module provides functions to implement transfer content encodings |
@@ -10,7 +10,14 @@ | |||
10 | * | 10 | * |
11 | * RCS ID: $Id$ | 11 | * RCS ID: $Id$ |
12 | \*=========================================================================*/ | 12 | \*=========================================================================*/ |
13 | #include <lua.h> | 13 | #include "lua.h" |
14 | |||
15 | /*-------------------------------------------------------------------------*\ | ||
16 | * Current MIME library version | ||
17 | \*-------------------------------------------------------------------------*/ | ||
18 | #define MIME_VERSION "MIME 1.0" | ||
19 | #define MIME_COPYRIGHT "Copyright (C) 2004-2005 Diego Nehab" | ||
20 | #define MIME_AUTHORS "Diego Nehab" | ||
14 | 21 | ||
15 | /*-------------------------------------------------------------------------*\ | 22 | /*-------------------------------------------------------------------------*\ |
16 | * This macro prefixes all exported API functions | 23 | * This macro prefixes all exported API functions |
diff --git a/src/options.c b/src/options.c index c9e69f0..5236a3f 100644 --- a/src/options.c +++ b/src/options.c | |||
@@ -4,9 +4,10 @@ | |||
4 | * | 4 | * |
5 | * RCS ID: $Id$ | 5 | * RCS ID: $Id$ |
6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
7 | #include <lauxlib.h> | ||
8 | #include <string.h> | 7 | #include <string.h> |
9 | 8 | ||
9 | #include "lauxlib.h" | ||
10 | |||
10 | #include "auxiliar.h" | 11 | #include "auxiliar.h" |
11 | #include "options.h" | 12 | #include "options.h" |
12 | #include "inet.h" | 13 | #include "inet.h" |
diff --git a/src/options.h b/src/options.h index d57bfaa..6ebf1f6 100644 --- a/src/options.h +++ b/src/options.h | |||
@@ -10,7 +10,7 @@ | |||
10 | * RCS ID: $Id$ | 10 | * RCS ID: $Id$ |
11 | \*=========================================================================*/ | 11 | \*=========================================================================*/ |
12 | 12 | ||
13 | #include <lua.h> | 13 | #include "lua.h" |
14 | #include "socket.h" | 14 | #include "socket.h" |
15 | 15 | ||
16 | /* option registry */ | 16 | /* option registry */ |
diff --git a/src/select.c b/src/select.c index e2cd91d..d28ade1 100644 --- a/src/select.c +++ b/src/select.c | |||
@@ -6,8 +6,8 @@ | |||
6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
7 | #include <string.h> | 7 | #include <string.h> |
8 | 8 | ||
9 | #include <lua.h> | 9 | #include "lua.h" |
10 | #include <lauxlib.h> | 10 | #include "lauxlib.h" |
11 | 11 | ||
12 | #include "socket.h" | 12 | #include "socket.h" |
13 | #include "timeout.h" | 13 | #include "timeout.h" |
diff --git a/src/socket.h b/src/socket.h index 4443bcc..ad12b1b 100644 --- a/src/socket.h +++ b/src/socket.h | |||
@@ -53,7 +53,6 @@ int sock_waitfd(p_sock ps, int sw, p_tm tm); | |||
53 | int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_tm tm); | 53 | int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_tm tm); |
54 | 54 | ||
55 | int sock_connect(p_sock ps, SA *addr, socklen_t addr_len, p_tm tm); | 55 | int sock_connect(p_sock ps, SA *addr, socklen_t addr_len, p_tm tm); |
56 | int sock_connected(p_sock ps, p_tm tm); | ||
57 | int sock_create(p_sock ps, int domain, int type, int protocol); | 56 | int sock_create(p_sock ps, int domain, int type, int protocol); |
58 | int sock_bind(p_sock ps, SA *addr, socklen_t addr_len); | 57 | int sock_bind(p_sock ps, SA *addr, socklen_t addr_len); |
59 | int sock_listen(p_sock ps, int backlog); | 58 | int sock_listen(p_sock ps, int backlog); |
@@ -6,8 +6,8 @@ | |||
6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
7 | #include <string.h> | 7 | #include <string.h> |
8 | 8 | ||
9 | #include <lua.h> | 9 | #include "lua.h" |
10 | #include <lauxlib.h> | 10 | #include "lauxlib.h" |
11 | 11 | ||
12 | #include "auxiliar.h" | 12 | #include "auxiliar.h" |
13 | #include "socket.h" | 13 | #include "socket.h" |
@@ -16,7 +16,7 @@ | |||
16 | * | 16 | * |
17 | * RCS ID: $Id$ | 17 | * RCS ID: $Id$ |
18 | \*=========================================================================*/ | 18 | \*=========================================================================*/ |
19 | #include <lua.h> | 19 | #include "lua.h" |
20 | 20 | ||
21 | #include "buffer.h" | 21 | #include "buffer.h" |
22 | #include "timeout.h" | 22 | #include "timeout.h" |
diff --git a/src/timeout.c b/src/timeout.c index be68228..4f1d345 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
@@ -6,8 +6,8 @@ | |||
6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | 8 | ||
9 | #include <lua.h> | 9 | #include "lua.h" |
10 | #include <lauxlib.h> | 10 | #include "lauxlib.h" |
11 | 11 | ||
12 | #include "auxiliar.h" | 12 | #include "auxiliar.h" |
13 | #include "timeout.h" | 13 | #include "timeout.h" |
diff --git a/src/timeout.h b/src/timeout.h index d2f9be0..27e0a8a 100644 --- a/src/timeout.h +++ b/src/timeout.h | |||
@@ -6,7 +6,7 @@ | |||
6 | * | 6 | * |
7 | * RCS ID: $Id$ | 7 | * RCS ID: $Id$ |
8 | \*=========================================================================*/ | 8 | \*=========================================================================*/ |
9 | #include <lua.h> | 9 | #include "lua.h" |
10 | 10 | ||
11 | /* timeout control structure */ | 11 | /* timeout control structure */ |
12 | typedef struct t_tm_ { | 12 | typedef struct t_tm_ { |
@@ -6,8 +6,8 @@ | |||
6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
7 | #include <string.h> | 7 | #include <string.h> |
8 | 8 | ||
9 | #include <lua.h> | 9 | #include "lua.h" |
10 | #include <lauxlib.h> | 10 | #include "lauxlib.h" |
11 | 11 | ||
12 | #include "auxiliar.h" | 12 | #include "auxiliar.h" |
13 | #include "socket.h" | 13 | #include "socket.h" |
@@ -14,7 +14,7 @@ | |||
14 | * | 14 | * |
15 | * RCS ID: $Id$ | 15 | * RCS ID: $Id$ |
16 | \*=========================================================================*/ | 16 | \*=========================================================================*/ |
17 | #include <lua.h> | 17 | #include "lua.h" |
18 | 18 | ||
19 | #include "timeout.h" | 19 | #include "timeout.h" |
20 | #include "socket.h" | 20 | #include "socket.h" |
@@ -6,8 +6,8 @@ | |||
6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
7 | #include <string.h> | 7 | #include <string.h> |
8 | 8 | ||
9 | #include <lua.h> | 9 | #include "lua.h" |
10 | #include <lauxlib.h> | 10 | #include "lauxlib.h" |
11 | 11 | ||
12 | #include "auxiliar.h" | 12 | #include "auxiliar.h" |
13 | #include "socket.h" | 13 | #include "socket.h" |
@@ -9,7 +9,7 @@ | |||
9 | * | 9 | * |
10 | * RCS ID: $Id$ | 10 | * RCS ID: $Id$ |
11 | \*=========================================================================*/ | 11 | \*=========================================================================*/ |
12 | #include <lua.h> | 12 | #include "lua.h" |
13 | 13 | ||
14 | #include "buffer.h" | 14 | #include "buffer.h" |
15 | #include "timeout.h" | 15 | #include "timeout.h" |
diff --git a/src/url.lua b/src/url.lua index bd39d98..5427cbc 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -15,6 +15,11 @@ module("socket.url") | |||
15 | getmetatable(_M).__index = nil | 15 | getmetatable(_M).__index = nil |
16 | 16 | ||
17 | ----------------------------------------------------------------------------- | 17 | ----------------------------------------------------------------------------- |
18 | -- Module version | ||
19 | ----------------------------------------------------------------------------- | ||
20 | _VERSION = "URL 1.0" | ||
21 | |||
22 | ----------------------------------------------------------------------------- | ||
18 | -- Encodes a string into its escaped hexadecimal representation | 23 | -- Encodes a string into its escaped hexadecimal representation |
19 | -- Input | 24 | -- Input |
20 | -- s: binary string to be encoded | 25 | -- s: binary string to be encoded |
diff --git a/src/usocket.c b/src/usocket.c index dcb40e6..f067fa1 100644 --- a/src/usocket.c +++ b/src/usocket.c | |||
@@ -169,15 +169,8 @@ int sock_connect(p_sock ps, SA *addr, socklen_t len, p_tm tm) { | |||
169 | /* zero timeout case optimization */ | 169 | /* zero timeout case optimization */ |
170 | if (tm_iszero(tm)) return IO_TIMEOUT; | 170 | if (tm_iszero(tm)) return IO_TIMEOUT; |
171 | /* wait until we have the result of the connection attempt or timeout */ | 171 | /* wait until we have the result of the connection attempt or timeout */ |
172 | return sock_connected(ps, tm); | 172 | err = sock_waitfd(ps, WAITFD_C, tm); |
173 | } | 173 | if (err == IO_CLOSED) { |
174 | |||
175 | /*-------------------------------------------------------------------------*\ | ||
176 | * Checks if socket is connected, or return reason for failure | ||
177 | \*-------------------------------------------------------------------------*/ | ||
178 | int sock_connected(p_sock ps, p_tm tm) { | ||
179 | int err; | ||
180 | if ((err = sock_waitfd(ps, WAITFD_C, tm) == IO_CLOSED)) { | ||
181 | if (recv(*ps, (char *) &err, 0, 0) == 0) return IO_DONE; | 174 | if (recv(*ps, (char *) &err, 0, 0) == 0) return IO_DONE; |
182 | else return errno; | 175 | else return errno; |
183 | } else return err; | 176 | } else return err; |
diff --git a/src/wsocket.c b/src/wsocket.c index 0f6005f..b533eae 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
@@ -22,7 +22,8 @@ int sock_open(void) { | |||
22 | WORD wVersionRequested = MAKEWORD(2, 0); | 22 | WORD wVersionRequested = MAKEWORD(2, 0); |
23 | int err = WSAStartup(wVersionRequested, &wsaData ); | 23 | int err = WSAStartup(wVersionRequested, &wsaData ); |
24 | if (err != 0) return 0; | 24 | if (err != 0) return 0; |
25 | if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0) { | 25 | if ((LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0) && |
26 | (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)) { | ||
26 | WSACleanup(); | 27 | WSACleanup(); |
27 | return 0; | 28 | return 0; |
28 | } | 29 | } |
@@ -124,16 +125,8 @@ int sock_connect(p_sock ps, SA *addr, socklen_t len, p_tm tm) { | |||
124 | /* zero timeout case optimization */ | 125 | /* zero timeout case optimization */ |
125 | if (tm_iszero(tm)) return IO_TIMEOUT; | 126 | if (tm_iszero(tm)) return IO_TIMEOUT; |
126 | /* we wait until something happens */ | 127 | /* we wait until something happens */ |
127 | return sock_connected(ps, tm); | 128 | err = sock_waitfd(ps, WAITFD_C, tm); |
128 | } | 129 | if (err == IO_CLOSED) { |
129 | |||
130 | /*-------------------------------------------------------------------------*\ | ||
131 | * Check if socket is connected | ||
132 | \*-------------------------------------------------------------------------*/ | ||
133 | int sock_connected(p_sock ps, p_tm tm) { | ||
134 | int err; | ||
135 | /* give windows time to find out what is up (yes, disgusting) */ | ||
136 | if ((err = sock_waitfd(ps, WAITFD_C, tm)) == IO_CLOSED) { | ||
137 | int len = sizeof(err); | 130 | int len = sizeof(err); |
138 | /* give windows time to set the error (yes, disgusting) */ | 131 | /* give windows time to set the error (yes, disgusting) */ |
139 | Sleep(10); | 132 | Sleep(10); |
@@ -143,6 +136,7 @@ int sock_connected(p_sock ps, p_tm tm) { | |||
143 | * "unknown error", but it's not really our fault */ | 136 | * "unknown error", but it's not really our fault */ |
144 | return err > 0? err: IO_UNKNOWN; | 137 | return err > 0? err: IO_UNKNOWN; |
145 | } else return err; | 138 | } else return err; |
139 | |||
146 | } | 140 | } |
147 | 141 | ||
148 | /*-------------------------------------------------------------------------*\ | 142 | /*-------------------------------------------------------------------------*\ |