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.
This commit is contained in:
Diego Nehab
2005-08-23 05:53:14 +00:00
parent 5e8ae76248
commit 773e35ced3
20 changed files with 454 additions and 364 deletions

View File

@ -127,6 +127,9 @@ void aux_setclass(lua_State *L, const char *classname, int objidx) {
* otherwise
\*-------------------------------------------------------------------------*/
void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) {
#if 0
return lua_touserdata(L, objidx);
#else
if (!lua_getmetatable(L, objidx))
return NULL;
lua_pushstring(L, groupname);
@ -138,6 +141,7 @@ void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) {
lua_pop(L, 2);
return lua_touserdata(L, objidx);
}
#endif
}
/*-------------------------------------------------------------------------*\
@ -145,5 +149,9 @@ void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) {
* otherwise
\*-------------------------------------------------------------------------*/
void *aux_getclassudata(lua_State *L, const char *classname, int objidx) {
#if 0
return lua_touserdata(L, objidx);
#else
return luaL_checkudata(L, objidx, classname);
#endif
}

View File

@ -325,4 +325,3 @@ request = socket.protect(function(reqt, body)
if base.type(reqt) == "string" then return srequest(reqt, body)
else return trequest(reqt) end
end)

View File

@ -27,6 +27,6 @@
/*-------------------------------------------------------------------------*\
* Initializes the library.
\*-------------------------------------------------------------------------*/
LUASOCKET_API int luaopen_socketcore(lua_State *L);
LUASOCKET_API int luaopen_socket_core(lua_State *L);
#endif /* LUASOCKET_H */

View File

@ -78,7 +78,7 @@ static UC b64unbase[256];
/*-------------------------------------------------------------------------*\
* Initializes module
\*-------------------------------------------------------------------------*/
MIME_API int luaopen_mimecore(lua_State *L)
MIME_API int luaopen_mime_core(lua_State *L)
{
luaL_openlib(L, "mime", func, 0);
/* initialize lookup tables */

View File

@ -19,6 +19,6 @@
#define MIME_API extern
#endif
MIME_API int luaopen_mimecore(lua_State *L);
MIME_API int luaopen_mime_core(lua_State *L);
#endif /* MIME_H */

View File

@ -137,12 +137,24 @@ end
-- send_message forward declaration
local send_message
-- yield the headers all at once, it's faster
local function send_headers(headers)
local h = "\r\n"
for i,v in base.pairs(headers) do
h = i .. ': ' .. v .. "\r\n" .. h
end
coroutine.yield(h)
end
-- yield multipart message body from a multipart message table
local function send_multipart(mesgt)
-- make sure we have our boundary and send headers
local bd = newboundary()
-- define boundary and finish headers
coroutine.yield('content-type: multipart/mixed; boundary="' ..
bd .. '"\r\n\r\n')
local headers = mesgt.headers or {}
headers['content-type'] = headers['content-type'] or 'multipart/mixed'
headers['content-type'] = headers['content-type'] ..
'; boundary="' .. bd .. '"'
send_headers(headers)
-- send preamble
if mesgt.body.preamble then
coroutine.yield(mesgt.body.preamble)
@ -164,11 +176,11 @@ end
-- yield message body from a source
local function send_source(mesgt)
-- set content-type if user didn't override
if not mesgt.headers or not mesgt.headers["content-type"] then
coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n\r\n')
else coroutine.yield("\r\n") end
-- finish headers
-- make sure we have a content-type
local headers = mesgt.headers or {}
headers['content-type'] = headers['content-type'] or
'text/plain; charset="iso-8859-1"'
send_headers(headers)
-- send body from source
while true do
local chunk, err = mesgt.body()
@ -180,28 +192,17 @@ end
-- yield message body from a string
local function send_string(mesgt)
-- set content-type if user didn't override
if not mesgt.headers or not mesgt.headers["content-type"] then
coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n\r\n')
else coroutine.yield("\r\n") end
-- make sure we have a content-type
local headers = mesgt.headers or {}
headers['content-type'] = headers['content-type'] or
'text/plain; charset="iso-8859-1"'
send_headers(headers)
-- send body from string
coroutine.yield(mesgt.body)
end
-- yield the headers all at once
local function send_headers(mesgt)
if mesgt.headers then
local h = ""
for i,v in base.pairs(mesgt.headers) do
h = i .. ': ' .. v .. "\r\n" .. h
end
coroutine.yield(h)
end
end
-- message source
function send_message(mesgt)
send_headers(mesgt)
if base.type(mesgt.body) == "table" then send_multipart(mesgt)
elseif base.type(mesgt.body) == "function" then send_source(mesgt)
else send_string(mesgt) end

View File

@ -75,7 +75,7 @@ int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_tm tm) {
tv.tv_sec = (int) t;
tv.tv_usec = (int) ((t - tv.tv_sec) * 1.0e6);
if (n <= 0) {
Sleep(1000*t);
Sleep((DWORD) (1000*t));
return 0;
} else return select(0, rfds, wfds, efds, t >= 0.0? &tv: NULL);
}