diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-08-23 05:53:14 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-08-23 05:53:14 +0000 |
| commit | 773e35ced30fa2c03ddb2a332bf8a9aebb56aa44 (patch) | |
| tree | 03e8e9a4bd64b9424006315c8e720c3f2841a751 /src | |
| parent | 5e8ae76248ed31496dc6fef7855498a0479159ed (diff) | |
| download | luasocket-773e35ced30fa2c03ddb2a332bf8a9aebb56aa44.tar.gz luasocket-773e35ced30fa2c03ddb2a332bf8a9aebb56aa44.tar.bz2 luasocket-773e35ced30fa2c03ddb2a332bf8a9aebb56aa44.zip | |
Compiled on Windows. Fixed a bunch of stuff. Almost ready to release.
Implemented a nice dispatcher! Non-blocking check-links and forward server
use the dispatcher.
Diffstat (limited to 'src')
| -rw-r--r-- | src/auxiliar.c | 8 | ||||
| -rw-r--r-- | src/http.lua | 1 | ||||
| -rw-r--r-- | src/luasocket.h | 2 | ||||
| -rw-r--r-- | src/mime.c | 2 | ||||
| -rw-r--r-- | src/mime.h | 2 | ||||
| -rw-r--r-- | src/smtp.lua | 49 | ||||
| -rw-r--r-- | src/wsocket.c | 2 |
7 files changed, 37 insertions, 29 deletions
diff --git a/src/auxiliar.c b/src/auxiliar.c index 2ebcdd6..b228785 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c | |||
| @@ -127,6 +127,9 @@ void aux_setclass(lua_State *L, const char *classname, int objidx) { | |||
| 127 | * otherwise | 127 | * otherwise |
| 128 | \*-------------------------------------------------------------------------*/ | 128 | \*-------------------------------------------------------------------------*/ |
| 129 | void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) { | 129 | void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) { |
| 130 | #if 0 | ||
| 131 | return lua_touserdata(L, objidx); | ||
| 132 | #else | ||
| 130 | if (!lua_getmetatable(L, objidx)) | 133 | if (!lua_getmetatable(L, objidx)) |
| 131 | return NULL; | 134 | return NULL; |
| 132 | lua_pushstring(L, groupname); | 135 | lua_pushstring(L, groupname); |
| @@ -138,6 +141,7 @@ void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) { | |||
| 138 | lua_pop(L, 2); | 141 | lua_pop(L, 2); |
| 139 | return lua_touserdata(L, objidx); | 142 | return lua_touserdata(L, objidx); |
| 140 | } | 143 | } |
| 144 | #endif | ||
| 141 | } | 145 | } |
| 142 | 146 | ||
| 143 | /*-------------------------------------------------------------------------*\ | 147 | /*-------------------------------------------------------------------------*\ |
| @@ -145,5 +149,9 @@ void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) { | |||
| 145 | * otherwise | 149 | * otherwise |
| 146 | \*-------------------------------------------------------------------------*/ | 150 | \*-------------------------------------------------------------------------*/ |
| 147 | void *aux_getclassudata(lua_State *L, const char *classname, int objidx) { | 151 | void *aux_getclassudata(lua_State *L, const char *classname, int objidx) { |
| 152 | #if 0 | ||
| 153 | return lua_touserdata(L, objidx); | ||
| 154 | #else | ||
| 148 | return luaL_checkudata(L, objidx, classname); | 155 | return luaL_checkudata(L, objidx, classname); |
| 156 | #endif | ||
| 149 | } | 157 | } |
diff --git a/src/http.lua b/src/http.lua index 9434d97..fe779a3 100644 --- a/src/http.lua +++ b/src/http.lua | |||
| @@ -325,4 +325,3 @@ request = socket.protect(function(reqt, body) | |||
| 325 | if base.type(reqt) == "string" then return srequest(reqt, body) | 325 | if base.type(reqt) == "string" then return srequest(reqt, body) |
| 326 | else return trequest(reqt) end | 326 | else return trequest(reqt) end |
| 327 | end) | 327 | end) |
| 328 | |||
diff --git a/src/luasocket.h b/src/luasocket.h index 34a7693..c7d09d8 100644 --- a/src/luasocket.h +++ b/src/luasocket.h | |||
| @@ -27,6 +27,6 @@ | |||
| 27 | /*-------------------------------------------------------------------------*\ | 27 | /*-------------------------------------------------------------------------*\ |
| 28 | * Initializes the library. | 28 | * Initializes the library. |
| 29 | \*-------------------------------------------------------------------------*/ | 29 | \*-------------------------------------------------------------------------*/ |
| 30 | LUASOCKET_API int luaopen_socketcore(lua_State *L); | 30 | LUASOCKET_API int luaopen_socket_core(lua_State *L); |
| 31 | 31 | ||
| 32 | #endif /* LUASOCKET_H */ | 32 | #endif /* LUASOCKET_H */ |
| @@ -78,7 +78,7 @@ static UC b64unbase[256]; | |||
| 78 | /*-------------------------------------------------------------------------*\ | 78 | /*-------------------------------------------------------------------------*\ |
| 79 | * Initializes module | 79 | * Initializes module |
| 80 | \*-------------------------------------------------------------------------*/ | 80 | \*-------------------------------------------------------------------------*/ |
| 81 | MIME_API int luaopen_mimecore(lua_State *L) | 81 | MIME_API int luaopen_mime_core(lua_State *L) |
| 82 | { | 82 | { |
| 83 | luaL_openlib(L, "mime", func, 0); | 83 | luaL_openlib(L, "mime", func, 0); |
| 84 | /* initialize lookup tables */ | 84 | /* initialize lookup tables */ |
| @@ -19,6 +19,6 @@ | |||
| 19 | #define MIME_API extern | 19 | #define MIME_API extern |
| 20 | #endif | 20 | #endif |
| 21 | 21 | ||
| 22 | MIME_API int luaopen_mimecore(lua_State *L); | 22 | MIME_API int luaopen_mime_core(lua_State *L); |
| 23 | 23 | ||
| 24 | #endif /* MIME_H */ | 24 | #endif /* MIME_H */ |
diff --git a/src/smtp.lua b/src/smtp.lua index 46df1ab..5c485c2 100644 --- a/src/smtp.lua +++ b/src/smtp.lua | |||
| @@ -137,12 +137,24 @@ end | |||
| 137 | -- send_message forward declaration | 137 | -- send_message forward declaration |
| 138 | local send_message | 138 | local send_message |
| 139 | 139 | ||
| 140 | -- yield the headers all at once, it's faster | ||
| 141 | local function send_headers(headers) | ||
| 142 | local h = "\r\n" | ||
| 143 | for i,v in base.pairs(headers) do | ||
| 144 | h = i .. ': ' .. v .. "\r\n" .. h | ||
| 145 | end | ||
| 146 | coroutine.yield(h) | ||
| 147 | end | ||
| 148 | |||
| 140 | -- yield multipart message body from a multipart message table | 149 | -- yield multipart message body from a multipart message table |
| 141 | local function send_multipart(mesgt) | 150 | local function send_multipart(mesgt) |
| 151 | -- make sure we have our boundary and send headers | ||
| 142 | local bd = newboundary() | 152 | local bd = newboundary() |
| 143 | -- define boundary and finish headers | 153 | local headers = mesgt.headers or {} |
| 144 | coroutine.yield('content-type: multipart/mixed; boundary="' .. | 154 | headers['content-type'] = headers['content-type'] or 'multipart/mixed' |
| 145 | bd .. '"\r\n\r\n') | 155 | headers['content-type'] = headers['content-type'] .. |
| 156 | '; boundary="' .. bd .. '"' | ||
| 157 | send_headers(headers) | ||
| 146 | -- send preamble | 158 | -- send preamble |
| 147 | if mesgt.body.preamble then | 159 | if mesgt.body.preamble then |
| 148 | coroutine.yield(mesgt.body.preamble) | 160 | coroutine.yield(mesgt.body.preamble) |
| @@ -164,11 +176,11 @@ end | |||
| 164 | 176 | ||
| 165 | -- yield message body from a source | 177 | -- yield message body from a source |
| 166 | local function send_source(mesgt) | 178 | local function send_source(mesgt) |
| 167 | -- set content-type if user didn't override | 179 | -- make sure we have a content-type |
| 168 | if not mesgt.headers or not mesgt.headers["content-type"] then | 180 | local headers = mesgt.headers or {} |
| 169 | coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n\r\n') | 181 | headers['content-type'] = headers['content-type'] or |
| 170 | else coroutine.yield("\r\n") end | 182 | 'text/plain; charset="iso-8859-1"' |
| 171 | -- finish headers | 183 | send_headers(headers) |
| 172 | -- send body from source | 184 | -- send body from source |
| 173 | while true do | 185 | while true do |
| 174 | local chunk, err = mesgt.body() | 186 | local chunk, err = mesgt.body() |
| @@ -180,28 +192,17 @@ end | |||
| 180 | 192 | ||
| 181 | -- yield message body from a string | 193 | -- yield message body from a string |
| 182 | local function send_string(mesgt) | 194 | local function send_string(mesgt) |
| 183 | -- set content-type if user didn't override | 195 | -- make sure we have a content-type |
| 184 | if not mesgt.headers or not mesgt.headers["content-type"] then | 196 | local headers = mesgt.headers or {} |
| 185 | coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n\r\n') | 197 | headers['content-type'] = headers['content-type'] or |
| 186 | else coroutine.yield("\r\n") end | 198 | 'text/plain; charset="iso-8859-1"' |
| 199 | send_headers(headers) | ||
| 187 | -- send body from string | 200 | -- send body from string |
| 188 | coroutine.yield(mesgt.body) | 201 | coroutine.yield(mesgt.body) |
| 189 | end | 202 | end |
| 190 | 203 | ||
| 191 | -- yield the headers all at once | ||
| 192 | local function send_headers(mesgt) | ||
| 193 | if mesgt.headers then | ||
| 194 | local h = "" | ||
| 195 | for i,v in base.pairs(mesgt.headers) do | ||
| 196 | h = i .. ': ' .. v .. "\r\n" .. h | ||
| 197 | end | ||
| 198 | coroutine.yield(h) | ||
| 199 | end | ||
| 200 | end | ||
| 201 | |||
| 202 | -- message source | 204 | -- message source |
| 203 | function send_message(mesgt) | 205 | function send_message(mesgt) |
| 204 | send_headers(mesgt) | ||
| 205 | if base.type(mesgt.body) == "table" then send_multipart(mesgt) | 206 | if base.type(mesgt.body) == "table" then send_multipart(mesgt) |
| 206 | elseif base.type(mesgt.body) == "function" then send_source(mesgt) | 207 | elseif base.type(mesgt.body) == "function" then send_source(mesgt) |
| 207 | else send_string(mesgt) end | 208 | else send_string(mesgt) end |
diff --git a/src/wsocket.c b/src/wsocket.c index c4c51b4..0f6005f 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
| @@ -75,7 +75,7 @@ int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_tm tm) { | |||
| 75 | tv.tv_sec = (int) t; | 75 | tv.tv_sec = (int) t; |
| 76 | tv.tv_usec = (int) ((t - tv.tv_sec) * 1.0e6); | 76 | tv.tv_usec = (int) ((t - tv.tv_sec) * 1.0e6); |
| 77 | if (n <= 0) { | 77 | if (n <= 0) { |
| 78 | Sleep(1000*t); | 78 | Sleep((DWORD) (1000*t)); |
| 79 | return 0; | 79 | return 0; |
| 80 | } else return select(0, rfds, wfds, efds, t >= 0.0? &tv: NULL); | 80 | } else return select(0, rfds, wfds, efds, t >= 0.0? &tv: NULL); |
| 81 | } | 81 | } |
