diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-20 07:20:26 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-11-20 07:20:26 +0000 |
| commit | f20f4889bfe5a02cd9b77868b90cc8042352176a (patch) | |
| tree | 339e085e385190ea5f3a9246c3a790c45036c61c | |
| parent | 087b4f865d861162eb32a4081bb7c2087688919a (diff) | |
| download | luasocket-f20f4889bfe5a02cd9b77868b90cc8042352176a.tar.gz luasocket-f20f4889bfe5a02cd9b77868b90cc8042352176a.tar.bz2 luasocket-f20f4889bfe5a02cd9b77868b90cc8042352176a.zip | |
Changed prefix of function names to match module names.
Removed some warnings and useless code.
| -rw-r--r-- | config | 20 | ||||
| -rw-r--r-- | mime.vcproj | 2 | ||||
| -rw-r--r-- | socket.vcproj | 6 | ||||
| -rw-r--r-- | src/mime.c | 57 | ||||
| -rw-r--r-- | src/options.c | 4 | ||||
| -rw-r--r-- | src/select.c | 37 | ||||
| -rw-r--r-- | src/socket.h | 3 | ||||
| -rw-r--r-- | src/url.lua | 29 | ||||
| -rw-r--r-- | src/usocket.c | 3 | ||||
| -rw-r--r-- | src/wsocket.c | 34 | ||||
| -rw-r--r-- | test/httptest.lua | 4 |
11 files changed, 110 insertions, 89 deletions
| @@ -37,20 +37,20 @@ INSTALL_EXEC=cp | |||
| 37 | # Compiler and linker settings | 37 | # Compiler and linker settings |
| 38 | # for Mac OS X | 38 | # for Mac OS X |
| 39 | # | 39 | # |
| 40 | CC=gcc | 40 | #CC=gcc |
| 41 | DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN | 41 | #DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN |
| 42 | CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common | 42 | #CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common |
| 43 | LDFLAGS=-bundle -undefined dynamic_lookup | 43 | #LDFLAGS=-bundle -undefined dynamic_lookup |
| 44 | LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc | 44 | #LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc |
| 45 | 45 | ||
| 46 | #------ | 46 | #------ |
| 47 | # Compiler and linker settings | 47 | # Compiler and linker settings |
| 48 | # for Linux | 48 | # for Linux |
| 49 | #CC=gcc | 49 | CC=gcc |
| 50 | #DEF=-DLUASOCKET_DEBUG | 50 | DEF=-DLUASOCKET_DEBUG |
| 51 | #CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic | 51 | CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic |
| 52 | #LDFLAGS=-O -shared | 52 | LDFLAGS=-O -shared |
| 53 | #LD=gcc | 53 | LD=gcc |
| 54 | 54 | ||
| 55 | #------ | 55 | #------ |
| 56 | # End of makefile configuration | 56 | # End of makefile configuration |
diff --git a/mime.vcproj b/mime.vcproj index f5c57c3..e5c4393 100644 --- a/mime.vcproj +++ b/mime.vcproj | |||
| @@ -72,7 +72,7 @@ | |||
| 72 | PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_EXPORTS; MIME_API=__declspec(dllexport)" | 72 | PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_EXPORTS; MIME_API=__declspec(dllexport)" |
| 73 | RuntimeLibrary="2" | 73 | RuntimeLibrary="2" |
| 74 | UsePrecompiledHeader="0" | 74 | UsePrecompiledHeader="0" |
| 75 | WarningLevel="3" | 75 | WarningLevel="4" |
| 76 | Detect64BitPortabilityProblems="TRUE" | 76 | Detect64BitPortabilityProblems="TRUE" |
| 77 | DebugInformationFormat="0"/> | 77 | DebugInformationFormat="0"/> |
| 78 | <Tool | 78 | <Tool |
diff --git a/socket.vcproj b/socket.vcproj index 133c902..abca5fb 100644 --- a/socket.vcproj +++ b/socket.vcproj | |||
| @@ -156,6 +156,12 @@ | |||
| 156 | </File> | 156 | </File> |
| 157 | <File | 157 | <File |
| 158 | RelativePath="src\wsocket.c"> | 158 | RelativePath="src\wsocket.c"> |
| 159 | <FileConfiguration | ||
| 160 | Name="Release|Win32"> | ||
| 161 | <Tool | ||
| 162 | Name="VCCLCompilerTool" | ||
| 163 | GeneratePreprocessedFile="0"/> | ||
| 164 | </FileConfiguration> | ||
| 159 | </File> | 165 | </File> |
| 160 | </Filter> | 166 | </Filter> |
| 161 | <Filter | 167 | <Filter |
| @@ -152,8 +152,8 @@ static int mime_global_wrp(lua_State *L) | |||
| 152 | static void b64setup(UC *b64unbase) | 152 | static void b64setup(UC *b64unbase) |
| 153 | { | 153 | { |
| 154 | int i; | 154 | int i; |
| 155 | for (i = 0; i < 255; i++) b64unbase[i] = 255; | 155 | for (i = 0; i <= 255; i++) b64unbase[i] = (UC) 255; |
| 156 | for (i = 0; i < 64; i++) b64unbase[b64base[i]] = i; | 156 | for (i = 0; i < 64; i++) b64unbase[b64base[i]] = (UC) i; |
| 157 | b64unbase['='] = 0; | 157 | b64unbase['='] = 0; |
| 158 | } | 158 | } |
| 159 | 159 | ||
| @@ -191,7 +191,7 @@ static size_t b64pad(const UC *input, size_t size, | |||
| 191 | luaL_Buffer *buffer) | 191 | luaL_Buffer *buffer) |
| 192 | { | 192 | { |
| 193 | unsigned long value = 0; | 193 | unsigned long value = 0; |
| 194 | UC code[4] = "===="; | 194 | UC code[4] = {'=', '=', '=', '='}; |
| 195 | switch (size) { | 195 | switch (size) { |
| 196 | case 1: | 196 | case 1: |
| 197 | value = input[0] << 4; | 197 | value = input[0] << 4; |
| @@ -480,38 +480,31 @@ static int mime_global_qp(lua_State *L) | |||
| 480 | * Accumulate characters until we are sure about how to deal with them. | 480 | * Accumulate characters until we are sure about how to deal with them. |
| 481 | * Once we are sure, output the to the buffer, in the correct form. | 481 | * Once we are sure, output the to the buffer, in the correct form. |
| 482 | \*-------------------------------------------------------------------------*/ | 482 | \*-------------------------------------------------------------------------*/ |
| 483 | static size_t qpdecode(UC c, UC *input, size_t size, | 483 | static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { |
| 484 | luaL_Buffer *buffer) | 484 | int d; |
| 485 | { | ||
| 486 | input[size++] = c; | 485 | input[size++] = c; |
| 487 | /* deal with all characters we can deal */ | 486 | /* deal with all characters we can deal */ |
| 488 | while (size > 0) { | 487 | switch (input[0]) { |
| 489 | int c, d; | 488 | /* if we have an escape character */ |
| 490 | switch (input[0]) { | 489 | case '=': |
| 491 | /* if we have an escape character */ | 490 | if (size < 3) return size; |
| 492 | case '=': | 491 | /* eliminate soft line break */ |
| 493 | if (size < 3) return size; | 492 | if (input[1] == '\r' && input[2] == '\n') return 0; |
| 494 | /* eliminate soft line break */ | 493 | /* decode quoted representation */ |
| 495 | if (input[1] == '\r' && input[2] == '\n') return 0; | 494 | c = qpunbase[input[1]]; d = qpunbase[input[2]]; |
| 496 | /* decode quoted representation */ | 495 | /* if it is an invalid, do not decode */ |
| 497 | c = qpunbase[input[1]]; d = qpunbase[input[2]]; | 496 | if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3); |
| 498 | /* if it is an invalid, do not decode */ | 497 | else luaL_putchar(buffer, (c << 4) + d); |
| 499 | if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3); | 498 | return 0; |
| 500 | else luaL_putchar(buffer, (c << 4) + d); | 499 | case '\r': |
| 501 | return 0; | 500 | if (size < 2) return size; |
| 502 | case '\r': | 501 | if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2); |
| 503 | if (size < 2) return size; | 502 | return 0; |
| 504 | if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2); | 503 | default: |
| 505 | return 0; | 504 | if (input[0] == '\t' || (input[0] > 31 && input[0] < 127)) |
| 506 | default: | 505 | luaL_putchar(buffer, input[0]); |
| 507 | if (input[0] == '\t' || (input[0] > 31 && input[0] < 127)) | 506 | return 0; |
| 508 | luaL_putchar(buffer, input[0]); | ||
| 509 | return 0; | ||
| 510 | } | ||
| 511 | input[0] = input[1]; input[1] = input[2]; | ||
| 512 | size--; | ||
| 513 | } | 507 | } |
| 514 | return 0; | ||
| 515 | } | 508 | } |
| 516 | 509 | ||
| 517 | /*-------------------------------------------------------------------------*\ | 510 | /*-------------------------------------------------------------------------*\ |
diff --git a/src/options.c b/src/options.c index 0f1ca2c..a464a4b 100644 --- a/src/options.c +++ b/src/options.c | |||
| @@ -80,12 +80,12 @@ int opt_linger(lua_State *L, p_socket ps) | |||
| 80 | lua_gettable(L, 3); | 80 | lua_gettable(L, 3); |
| 81 | if (!lua_isboolean(L, -1)) | 81 | if (!lua_isboolean(L, -1)) |
| 82 | luaL_argerror(L, 3, "boolean 'on' field expected"); | 82 | luaL_argerror(L, 3, "boolean 'on' field expected"); |
| 83 | li.l_onoff = lua_toboolean(L, -1); | 83 | li.l_onoff = (u_short) lua_toboolean(L, -1); |
| 84 | lua_pushstring(L, "timeout"); | 84 | lua_pushstring(L, "timeout"); |
| 85 | lua_gettable(L, 3); | 85 | lua_gettable(L, 3); |
| 86 | if (!lua_isnumber(L, -1)) | 86 | if (!lua_isnumber(L, -1)) |
| 87 | luaL_argerror(L, 3, "number 'timeout' field expected"); | 87 | luaL_argerror(L, 3, "number 'timeout' field expected"); |
| 88 | li.l_linger = (int) lua_tonumber(L, -1); | 88 | li.l_linger = (u_short) lua_tonumber(L, -1); |
| 89 | return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li)); | 89 | return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li)); |
| 90 | } | 90 | } |
| 91 | 91 | ||
diff --git a/src/select.c b/src/select.c index 5a3d502..99b59f5 100644 --- a/src/select.c +++ b/src/select.c | |||
| @@ -16,11 +16,12 @@ | |||
| 16 | /*=========================================================================*\ | 16 | /*=========================================================================*\ |
| 17 | * Internal function prototypes. | 17 | * Internal function prototypes. |
| 18 | \*=========================================================================*/ | 18 | \*=========================================================================*/ |
| 19 | static int getfd(lua_State *L); | 19 | static t_socket getfd(lua_State *L); |
| 20 | static int dirty(lua_State *L); | 20 | static int dirty(lua_State *L); |
| 21 | static int collect_fd(lua_State *L, int tab, int max_fd, int itab, fd_set *set); | 21 | static t_socket collect_fd(lua_State *L, int tab, t_socket max_fd, |
| 22 | int itab, fd_set *set); | ||
| 22 | static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set); | 23 | static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set); |
| 23 | static void return_fd(lua_State *L, fd_set *set, int max_fd, | 24 | static void return_fd(lua_State *L, fd_set *set, t_socket max_fd, |
| 24 | int itab, int tab, int start); | 25 | int itab, int tab, int start); |
| 25 | static void make_assoc(lua_State *L, int tab); | 26 | static void make_assoc(lua_State *L, int tab); |
| 26 | static int global_select(lua_State *L); | 27 | static int global_select(lua_State *L); |
| @@ -49,7 +50,8 @@ int select_open(lua_State *L) { | |||
| 49 | * Waits for a set of sockets until a condition is met or timeout. | 50 | * Waits for a set of sockets until a condition is met or timeout. |
| 50 | \*-------------------------------------------------------------------------*/ | 51 | \*-------------------------------------------------------------------------*/ |
| 51 | static int global_select(lua_State *L) { | 52 | static int global_select(lua_State *L) { |
| 52 | int rtab, wtab, itab, max_fd, ret, ndirty; | 53 | int rtab, wtab, itab, ret, ndirty; |
| 54 | t_socket max_fd; | ||
| 53 | fd_set rset, wset; | 55 | fd_set rset, wset; |
| 54 | t_timeout tm; | 56 | t_timeout tm; |
| 55 | double t = luaL_optnumber(L, 3, -1); | 57 | double t = luaL_optnumber(L, 3, -1); |
| @@ -58,7 +60,7 @@ static int global_select(lua_State *L) { | |||
| 58 | lua_newtable(L); itab = lua_gettop(L); | 60 | lua_newtable(L); itab = lua_gettop(L); |
| 59 | lua_newtable(L); rtab = lua_gettop(L); | 61 | lua_newtable(L); rtab = lua_gettop(L); |
| 60 | lua_newtable(L); wtab = lua_gettop(L); | 62 | lua_newtable(L); wtab = lua_gettop(L); |
| 61 | max_fd = collect_fd(L, 1, -1, itab, &rset); | 63 | max_fd = collect_fd(L, 1, SOCKET_INVALID, itab, &rset); |
| 62 | ndirty = check_dirty(L, 1, rtab, &rset); | 64 | ndirty = check_dirty(L, 1, rtab, &rset); |
| 63 | t = ndirty > 0? 0.0: t; | 65 | t = ndirty > 0? 0.0: t; |
| 64 | timeout_init(&tm, t, -1); | 66 | timeout_init(&tm, t, -1); |
| @@ -83,15 +85,15 @@ static int global_select(lua_State *L) { | |||
| 83 | /*=========================================================================*\ | 85 | /*=========================================================================*\ |
| 84 | * Internal functions | 86 | * Internal functions |
| 85 | \*=========================================================================*/ | 87 | \*=========================================================================*/ |
| 86 | static int getfd(lua_State *L) { | 88 | static t_socket getfd(lua_State *L) { |
| 87 | int fd = -1; | 89 | t_socket fd = SOCKET_INVALID; |
| 88 | lua_pushstring(L, "getfd"); | 90 | lua_pushstring(L, "getfd"); |
| 89 | lua_gettable(L, -2); | 91 | lua_gettable(L, -2); |
| 90 | if (!lua_isnil(L, -1)) { | 92 | if (!lua_isnil(L, -1)) { |
| 91 | lua_pushvalue(L, -2); | 93 | lua_pushvalue(L, -2); |
| 92 | lua_call(L, 1, 1); | 94 | lua_call(L, 1, 1); |
| 93 | if (lua_isnumber(L, -1)) | 95 | if (lua_isnumber(L, -1)) |
| 94 | fd = (int) lua_tonumber(L, -1); | 96 | fd = (t_socket) lua_tonumber(L, -1); |
| 95 | } | 97 | } |
| 96 | lua_pop(L, 1); | 98 | lua_pop(L, 1); |
| 97 | return fd; | 99 | return fd; |
| @@ -110,13 +112,13 @@ static int dirty(lua_State *L) { | |||
| 110 | return is; | 112 | return is; |
| 111 | } | 113 | } |
| 112 | 114 | ||
| 113 | static int collect_fd(lua_State *L, int tab, int max_fd, | 115 | static t_socket collect_fd(lua_State *L, int tab, t_socket max_fd, |
| 114 | int itab, fd_set *set) { | 116 | int itab, fd_set *set) { |
| 115 | int i = 1; | 117 | int i = 1; |
| 116 | if (lua_isnil(L, tab)) | 118 | if (lua_isnil(L, tab)) |
| 117 | return max_fd; | 119 | return max_fd; |
| 118 | while (1) { | 120 | while (1) { |
| 119 | int fd; | 121 | t_socket fd; |
| 120 | lua_pushnumber(L, i); | 122 | lua_pushnumber(L, i); |
| 121 | lua_gettable(L, tab); | 123 | lua_gettable(L, tab); |
| 122 | if (lua_isnil(L, -1)) { | 124 | if (lua_isnil(L, -1)) { |
| @@ -124,9 +126,10 @@ static int collect_fd(lua_State *L, int tab, int max_fd, | |||
| 124 | break; | 126 | break; |
| 125 | } | 127 | } |
| 126 | fd = getfd(L); | 128 | fd = getfd(L); |
| 127 | if (fd >= 0) { | 129 | if (fd != SOCKET_INVALID) { |
| 128 | FD_SET(fd, set); | 130 | FD_SET(fd, set); |
| 129 | if (max_fd < fd) max_fd = fd; | 131 | if (max_fd == SOCKET_INVALID || max_fd < fd) |
| 132 | max_fd = fd; | ||
| 130 | lua_pushnumber(L, fd); | 133 | lua_pushnumber(L, fd); |
| 131 | lua_pushvalue(L, -2); | 134 | lua_pushvalue(L, -2); |
| 132 | lua_settable(L, itab); | 135 | lua_settable(L, itab); |
| @@ -141,8 +144,8 @@ static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) { | |||
| 141 | int ndirty = 0, i = 1; | 144 | int ndirty = 0, i = 1; |
| 142 | if (lua_isnil(L, tab)) | 145 | if (lua_isnil(L, tab)) |
| 143 | return 0; | 146 | return 0; |
| 144 | while (1) { | 147 | while (1) { |
| 145 | int fd; | 148 | t_socket fd; |
| 146 | lua_pushnumber(L, i); | 149 | lua_pushnumber(L, i); |
| 147 | lua_gettable(L, tab); | 150 | lua_gettable(L, tab); |
| 148 | if (lua_isnil(L, -1)) { | 151 | if (lua_isnil(L, -1)) { |
| @@ -150,7 +153,7 @@ static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) { | |||
| 150 | break; | 153 | break; |
| 151 | } | 154 | } |
| 152 | fd = getfd(L); | 155 | fd = getfd(L); |
| 153 | if (fd >= 0 && dirty(L)) { | 156 | if (fd != SOCKET_INVALID && dirty(L)) { |
| 154 | lua_pushnumber(L, ++ndirty); | 157 | lua_pushnumber(L, ++ndirty); |
| 155 | lua_pushvalue(L, -2); | 158 | lua_pushvalue(L, -2); |
| 156 | lua_settable(L, dtab); | 159 | lua_settable(L, dtab); |
| @@ -162,9 +165,9 @@ static int check_dirty(lua_State *L, int tab, int dtab, fd_set *set) { | |||
| 162 | return ndirty; | 165 | return ndirty; |
| 163 | } | 166 | } |
| 164 | 167 | ||
| 165 | static void return_fd(lua_State *L, fd_set *set, int max_fd, | 168 | static void return_fd(lua_State *L, fd_set *set, t_socket max_fd, |
| 166 | int itab, int tab, int start) { | 169 | int itab, int tab, int start) { |
| 167 | int fd; | 170 | t_socket fd; |
| 168 | for (fd = 0; fd < max_fd; fd++) { | 171 | for (fd = 0; fd < max_fd; fd++) { |
| 169 | if (FD_ISSET(fd, set)) { | 172 | if (FD_ISSET(fd, set)) { |
| 170 | lua_pushnumber(L, ++start); | 173 | lua_pushnumber(L, ++start); |
diff --git a/src/socket.h b/src/socket.h index a599d8a..de5d79f 100644 --- a/src/socket.h +++ b/src/socket.h | |||
| @@ -50,7 +50,8 @@ void socket_setnonblocking(p_socket ps); | |||
| 50 | void socket_setblocking(p_socket ps); | 50 | void socket_setblocking(p_socket ps); |
| 51 | 51 | ||
| 52 | int socket_waitfd(p_socket ps, int sw, p_timeout tm); | 52 | int socket_waitfd(p_socket ps, int sw, p_timeout tm); |
| 53 | int socket_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm); | 53 | int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, |
| 54 | p_timeout tm); | ||
| 54 | 55 | ||
| 55 | int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); | 56 | int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); |
| 56 | int socket_create(p_socket ps, int domain, int type, int protocol); | 57 | int socket_create(p_socket ps, int domain, int type, int protocol); |
diff --git a/src/url.lua b/src/url.lua index ec62ad6..52e88da 100644 --- a/src/url.lua +++ b/src/url.lua | |||
| @@ -130,29 +130,41 @@ function parse(url, default) | |||
| 130 | -- remove whitespace | 130 | -- remove whitespace |
| 131 | -- url = string.gsub(url, "%s", "") | 131 | -- url = string.gsub(url, "%s", "") |
| 132 | -- get fragment | 132 | -- get fragment |
| 133 | url = string.gsub(url, "#(.*)$", function(f) parsed.fragment = f end) | 133 | url = string.gsub(url, "#(.*)$", function(f) |
| 134 | parsed.fragment = f | ||
| 135 | return "" | ||
| 136 | end) | ||
| 134 | -- get scheme | 137 | -- get scheme |
| 135 | url = string.gsub(url, "^([%w][%w%+%-%.]*)%:", | 138 | url = string.gsub(url, "^([%w][%w%+%-%.]*)%:", |
| 136 | function(s) parsed.scheme = s end) | 139 | function(s) parsed.scheme = s; return "" end) |
| 137 | -- get authority | 140 | -- get authority |
| 138 | url = string.gsub(url, "^//([^/]*)", function(n) parsed.authority = n end) | 141 | url = string.gsub(url, "^//([^/]*)", function(n) |
| 142 | parsed.authority = n | ||
| 143 | return "" | ||
| 144 | end) | ||
| 139 | -- get query stringing | 145 | -- get query stringing |
| 140 | url = string.gsub(url, "%?(.*)", function(q) parsed.query = q end) | 146 | url = string.gsub(url, "%?(.*)", function(q) |
| 147 | parsed.query = q | ||
| 148 | return "" | ||
| 149 | end) | ||
| 141 | -- get params | 150 | -- get params |
| 142 | url = string.gsub(url, "%;(.*)", function(p) parsed.params = p end) | 151 | url = string.gsub(url, "%;(.*)", function(p) |
| 152 | parsed.params = p | ||
| 153 | return "" | ||
| 154 | end) | ||
| 143 | -- path is whatever was left | 155 | -- path is whatever was left |
| 144 | if url ~= "" then parsed.path = url end | 156 | if url ~= "" then parsed.path = url end |
| 145 | local authority = parsed.authority | 157 | local authority = parsed.authority |
| 146 | if not authority then return parsed end | 158 | if not authority then return parsed end |
| 147 | authority = string.gsub(authority,"^([^@]*)@", | 159 | authority = string.gsub(authority,"^([^@]*)@", |
| 148 | function(u) parsed.userinfo = u end) | 160 | function(u) parsed.userinfo = u; return "" end) |
| 149 | authority = string.gsub(authority, ":([^:]*)$", | 161 | authority = string.gsub(authority, ":([^:]*)$", |
| 150 | function(p) parsed.port = p end) | 162 | function(p) parsed.port = p; return "" end) |
| 151 | if authority ~= "" then parsed.host = authority end | 163 | if authority ~= "" then parsed.host = authority end |
| 152 | local userinfo = parsed.userinfo | 164 | local userinfo = parsed.userinfo |
| 153 | if not userinfo then return parsed end | 165 | if not userinfo then return parsed end |
| 154 | userinfo = string.gsub(userinfo, ":([^:]*)$", | 166 | userinfo = string.gsub(userinfo, ":([^:]*)$", |
| 155 | function(p) parsed.password = p end) | 167 | function(p) parsed.password = p; return "" end) |
| 156 | parsed.user = userinfo | 168 | parsed.user = userinfo |
| 157 | return parsed | 169 | return parsed |
| 158 | end | 170 | end |
| @@ -283,4 +295,3 @@ function build_path(parsed, unsafe) | |||
| 283 | if parsed.is_absolute then path = "/" .. path end | 295 | if parsed.is_absolute then path = "/" .. path end |
| 284 | return path | 296 | return path |
| 285 | end | 297 | end |
| 286 | |||
diff --git a/src/usocket.c b/src/usocket.c index e9db6dd..6a0b178 100644 --- a/src/usocket.c +++ b/src/usocket.c | |||
| @@ -102,7 +102,8 @@ void socket_destroy(p_socket ps) { | |||
| 102 | /*-------------------------------------------------------------------------*\ | 102 | /*-------------------------------------------------------------------------*\ |
| 103 | * Select with timeout control | 103 | * Select with timeout control |
| 104 | \*-------------------------------------------------------------------------*/ | 104 | \*-------------------------------------------------------------------------*/ |
| 105 | int socket_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm) { | 105 | int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, |
| 106 | p_timeout tm) { | ||
| 106 | int ret; | 107 | int ret; |
| 107 | do { | 108 | do { |
| 108 | struct timeval tv; | 109 | struct timeval tv; |
diff --git a/src/wsocket.c b/src/wsocket.c index a690dad..dce333b 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
| @@ -46,16 +46,20 @@ int socket_close(void) { | |||
| 46 | #define WAITFD_E 4 | 46 | #define WAITFD_E 4 |
| 47 | #define WAITFD_C (WAITFD_E|WAITFD_W) | 47 | #define WAITFD_C (WAITFD_E|WAITFD_W) |
| 48 | 48 | ||
| 49 | int socket_waitfd(p_socket ps, int sw, p_tm tm) { | 49 | int socket_waitfd(p_socket ps, int sw, p_timeout tm) { |
| 50 | int ret; | 50 | int ret; |
| 51 | fd_set rfds, wfds, efds, *rp = NULL, *wp = NULL, *ep = NULL; | 51 | fd_set rfds, wfds, efds, *rp = NULL, *wp = NULL, *ep = NULL; |
| 52 | struct timeval tv, *tp = NULL; | 52 | struct timeval tv, *tp = NULL; |
| 53 | double t; | 53 | double t; |
| 54 | if (tm_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */ | 54 | if (timeout_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */ |
| 55 | if (sw & WAITFD_R) { FD_ZERO(&rfds); FD_SET(*ps, &rfds); rp = &rfds; } | 55 | if (sw & WAITFD_R) { |
| 56 | FD_ZERO(&rfds); | ||
| 57 | FD_SET(*ps, &rfds); | ||
| 58 | rp = &rfds; | ||
| 59 | } | ||
| 56 | if (sw & WAITFD_W) { FD_ZERO(&wfds); FD_SET(*ps, &wfds); wp = &wfds; } | 60 | if (sw & WAITFD_W) { FD_ZERO(&wfds); FD_SET(*ps, &wfds); wp = &wfds; } |
| 57 | if (sw & WAITFD_C) { FD_ZERO(&efds); FD_SET(*ps, &efds); ep = &efds; } | 61 | if (sw & WAITFD_C) { FD_ZERO(&efds); FD_SET(*ps, &efds); ep = &efds; } |
| 58 | if ((t = tm_get(tm)) >= 0.0) { | 62 | if ((t = timeout_get(tm)) >= 0.0) { |
| 59 | tv.tv_sec = (int) t; | 63 | tv.tv_sec = (int) t; |
| 60 | tv.tv_usec = (int) ((t-tv.tv_sec)*1.0e6); | 64 | tv.tv_usec = (int) ((t-tv.tv_sec)*1.0e6); |
| 61 | tp = &tv; | 65 | tp = &tv; |
| @@ -70,9 +74,10 @@ int socket_waitfd(p_socket ps, int sw, p_tm tm) { | |||
| 70 | /*-------------------------------------------------------------------------*\ | 74 | /*-------------------------------------------------------------------------*\ |
| 71 | * Select with int timeout in ms | 75 | * Select with int timeout in ms |
| 72 | \*-------------------------------------------------------------------------*/ | 76 | \*-------------------------------------------------------------------------*/ |
| 73 | int socket_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_tm tm) { | 77 | int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, |
| 78 | p_timeout tm) { | ||
| 74 | struct timeval tv; | 79 | struct timeval tv; |
| 75 | double t = tm_get(tm); | 80 | double t = timeout_get(tm); |
| 76 | tv.tv_sec = (int) t; | 81 | tv.tv_sec = (int) t; |
| 77 | tv.tv_usec = (int) ((t - tv.tv_sec) * 1.0e6); | 82 | tv.tv_usec = (int) ((t - tv.tv_sec) * 1.0e6); |
| 78 | if (n <= 0) { | 83 | if (n <= 0) { |
| @@ -113,7 +118,7 @@ int socket_create(p_socket ps, int domain, int type, int protocol) { | |||
| 113 | /*-------------------------------------------------------------------------*\ | 118 | /*-------------------------------------------------------------------------*\ |
| 114 | * Connects or returns error message | 119 | * Connects or returns error message |
| 115 | \*-------------------------------------------------------------------------*/ | 120 | \*-------------------------------------------------------------------------*/ |
| 116 | int socket_connect(p_socket ps, SA *addr, socklen_t len, p_tm tm) { | 121 | int socket_connect(p_socket ps, SA *addr, socklen_t len, p_timeout tm) { |
| 117 | int err; | 122 | int err; |
| 118 | /* don't call on closed socket */ | 123 | /* don't call on closed socket */ |
| 119 | if (*ps == SOCKET_INVALID) return IO_CLOSED; | 124 | if (*ps == SOCKET_INVALID) return IO_CLOSED; |
| @@ -123,7 +128,7 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_tm tm) { | |||
| 123 | err = WSAGetLastError(); | 128 | err = WSAGetLastError(); |
| 124 | if (err != WSAEWOULDBLOCK && err != WSAEINPROGRESS) return err; | 129 | if (err != WSAEWOULDBLOCK && err != WSAEINPROGRESS) return err; |
| 125 | /* zero timeout case optimization */ | 130 | /* zero timeout case optimization */ |
| 126 | if (tm_iszero(tm)) return IO_TIMEOUT; | 131 | if (timeout_iszero(tm)) return IO_TIMEOUT; |
| 127 | /* we wait until something happens */ | 132 | /* we wait until something happens */ |
| 128 | err = socket_waitfd(ps, WAITFD_C, tm); | 133 | err = socket_waitfd(ps, WAITFD_C, tm); |
| 129 | if (err == IO_CLOSED) { | 134 | if (err == IO_CLOSED) { |
| @@ -131,7 +136,7 @@ int socket_connect(p_socket ps, SA *addr, socklen_t len, p_tm tm) { | |||
| 131 | /* give windows time to set the error (yes, disgusting) */ | 136 | /* give windows time to set the error (yes, disgusting) */ |
| 132 | Sleep(10); | 137 | Sleep(10); |
| 133 | /* find out why we failed */ | 138 | /* find out why we failed */ |
| 134 | getsockopt(*ps, SOL_SOCKETET, SO_ERROR, (char *)&err, &len); | 139 | getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &len); |
| 135 | /* we KNOW there was an error. if 'why' is 0, we will return | 140 | /* we KNOW there was an error. if 'why' is 0, we will return |
| 136 | * "unknown error", but it's not really our fault */ | 141 | * "unknown error", but it's not really our fault */ |
| 137 | return err > 0? err: IO_UNKNOWN; | 142 | return err > 0? err: IO_UNKNOWN; |
| @@ -164,7 +169,8 @@ int socket_listen(p_socket ps, int backlog) { | |||
| 164 | /*-------------------------------------------------------------------------*\ | 169 | /*-------------------------------------------------------------------------*\ |
| 165 | * Accept with timeout | 170 | * Accept with timeout |
| 166 | \*-------------------------------------------------------------------------*/ | 171 | \*-------------------------------------------------------------------------*/ |
| 167 | int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_tm tm) { | 172 | int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, |
| 173 | p_timeout tm) { | ||
| 168 | SA daddr; | 174 | SA daddr; |
| 169 | socklen_t dlen = sizeof(daddr); | 175 | socklen_t dlen = sizeof(daddr); |
| 170 | if (*ps == SOCKET_INVALID) return IO_CLOSED; | 176 | if (*ps == SOCKET_INVALID) return IO_CLOSED; |
| @@ -192,7 +198,7 @@ int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *len, p_tm tm) { | |||
| 192 | * Therefore, whoever calls this function should not pass a huge buffer. | 198 | * Therefore, whoever calls this function should not pass a huge buffer. |
| 193 | \*-------------------------------------------------------------------------*/ | 199 | \*-------------------------------------------------------------------------*/ |
| 194 | int socket_send(p_socket ps, const char *data, size_t count, | 200 | int socket_send(p_socket ps, const char *data, size_t count, |
| 195 | size_t *sent, p_tm tm) | 201 | size_t *sent, p_timeout tm) |
| 196 | { | 202 | { |
| 197 | int err; | 203 | int err; |
| 198 | /* avoid making system calls on closed sockets */ | 204 | /* avoid making system calls on closed sockets */ |
| @@ -222,7 +228,7 @@ int socket_send(p_socket ps, const char *data, size_t count, | |||
| 222 | * Sendto with timeout | 228 | * Sendto with timeout |
| 223 | \*-------------------------------------------------------------------------*/ | 229 | \*-------------------------------------------------------------------------*/ |
| 224 | int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, | 230 | int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, |
| 225 | SA *addr, socklen_t len, p_tm tm) | 231 | SA *addr, socklen_t len, p_timeout tm) |
| 226 | { | 232 | { |
| 227 | int err; | 233 | int err; |
| 228 | if (*ps == SOCKET_INVALID) return IO_CLOSED; | 234 | if (*ps == SOCKET_INVALID) return IO_CLOSED; |
| @@ -243,7 +249,7 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, | |||
| 243 | /*-------------------------------------------------------------------------*\ | 249 | /*-------------------------------------------------------------------------*\ |
| 244 | * Receive with timeout | 250 | * Receive with timeout |
| 245 | \*-------------------------------------------------------------------------*/ | 251 | \*-------------------------------------------------------------------------*/ |
| 246 | int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_tm tm) { | 252 | int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) { |
| 247 | int err; | 253 | int err; |
| 248 | if (*ps == SOCKET_INVALID) return IO_CLOSED; | 254 | if (*ps == SOCKET_INVALID) return IO_CLOSED; |
| 249 | *got = 0; | 255 | *got = 0; |
| @@ -265,7 +271,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_tm tm) { | |||
| 265 | * Recvfrom with timeout | 271 | * Recvfrom with timeout |
| 266 | \*-------------------------------------------------------------------------*/ | 272 | \*-------------------------------------------------------------------------*/ |
| 267 | int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, | 273 | int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, |
| 268 | SA *addr, socklen_t *len, p_tm tm) { | 274 | SA *addr, socklen_t *len, p_timeout tm) { |
| 269 | int err; | 275 | int err; |
| 270 | if (*ps == SOCKET_INVALID) return IO_CLOSED; | 276 | if (*ps == SOCKET_INVALID) return IO_CLOSED; |
| 271 | *got = 0; | 277 | *got = 0; |
diff --git a/test/httptest.lua b/test/httptest.lua index 3816b54..0951389 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
| @@ -22,8 +22,8 @@ http.TIMEOUT = 10 | |||
| 22 | 22 | ||
| 23 | local t = socket.gettime() | 23 | local t = socket.gettime() |
| 24 | 24 | ||
| 25 | host = host or "localhost" -- "diego.student.princeton.edu" | 25 | host = host or "dell-diego" -- "diego.student.princeton.edu" |
| 26 | proxy = proxy or "http://localhost:3128" | 26 | proxy = proxy or "http://dell-diego:3128" |
| 27 | prefix = prefix or "/luasocket-test" | 27 | prefix = prefix or "/luasocket-test" |
| 28 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | 28 | cgiprefix = cgiprefix or "/luasocket-test-cgi" |
| 29 | index_file = "index.html" | 29 | index_file = "index.html" |
