diff options
author | Jan Kneschke <jan@kneschke.de> | 2006-10-06 08:27:50 +0000 |
---|---|---|
committer | Jan Kneschke <jan@kneschke.de> | 2006-10-06 08:27:50 +0000 |
commit | 360a20c2daf09ef0315c921afb33de4d5b876614 (patch) | |
tree | 0a5de93683810bc49e2b2c0133ef845ded5e1c7d | |
parent | 4c7567a49f070e4a3d22d6ad4470c67552a8aef6 (diff) | |
download | lighttpd-git-360a20c2daf09ef0315c921afb33de4d5b876614.tar.gz |
added lighty.stat() which uses the stat-cache to reduce the number of syscalls
git-svn-id: svn+ssh://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@1377 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r-- | src/mod_magnet.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/mod_magnet.c b/src/mod_magnet.c index a75b849d..100ec91b 100644 --- a/src/mod_magnet.c +++ b/src/mod_magnet.c @@ -14,6 +14,7 @@ #include "response.h" #include "stat_cache.h" #include "status_counter.h" +#include "etag.h" #ifdef HAVE_LUA_H #include <lua.h> @@ -172,6 +173,71 @@ static int magnet_print(lua_State *L) { return 0; } +static int magnet_stat(lua_State *L) { + const char *s = luaL_checkstring(L, 1); + server *srv; + connection *con; + buffer sb, *b; + stat_cache_entry *sce = NULL; + + lua_pushstring(L, "lighty.srv"); + lua_gettable(L, LUA_REGISTRYINDEX); + srv = lua_touserdata(L, -1); + lua_pop(L, 1); + + lua_pushstring(L, "lighty.con"); + lua_gettable(L, LUA_REGISTRYINDEX); + con = lua_touserdata(L, -1); + lua_pop(L, 1); + + sb.ptr = (char *)s; + sb.used = sb.size = strlen(s) + 1; + + if (HANDLER_GO_ON != stat_cache_get_entry(srv, con, &sb, &sce)) { + lua_pushnil(L); + + return 1; + } + + lua_newtable(L); + lua_pushinteger(L, sce->st.st_mode); + lua_setfield(L, -2, "st_mode"); + + lua_pushinteger(L, sce->st.st_mtime); + lua_setfield(L, -2, "st_mtime"); + + lua_pushinteger(L, sce->st.st_ctime); + lua_setfield(L, -2, "st_ctime"); + + lua_pushinteger(L, sce->st.st_atime); + lua_setfield(L, -2, "st_atime"); + + lua_pushinteger(L, sce->st.st_uid); + lua_setfield(L, -2, "st_uid"); + + lua_pushinteger(L, sce->st.st_gid); + lua_setfield(L, -2, "st_gid"); + + lua_pushinteger(L, sce->st.st_size); + lua_setfield(L, -2, "st_size"); + + lua_pushinteger(L, sce->st.st_ino); + lua_setfield(L, -2, "st_ino"); + + /* we have to mutate the etag */ + + b = buffer_init(); + etag_mutate(b, sce->etag); + + lua_pushlstring(L, b->ptr, b->used - 1); + lua_setfield(L, -2, "etag"); + + buffer_free(b); + + return 1; +} + + static int magnet_atpanic(lua_State *L) { const char *s = luaL_checkstring(L, 1); server *srv; @@ -297,6 +363,7 @@ static buffer *magnet_env_get_buffer(server *srv, connection *con, const char *k { NULL, MAGNET_ENV_UNSET } }; + UNUSED(srv); /** * map all internal variables to lua @@ -388,6 +455,7 @@ static int magnet_env_set(lua_State *L) { static int magnet_copy_response_header(server *srv, connection *con, plugin_data *p, lua_State *L) { + UNUSED(p); /** * get the environment of the function */ @@ -436,6 +504,7 @@ static int magnet_copy_response_header(server *srv, connection *con, plugin_data * return 200 */ static int magnet_attach_content(server *srv, connection *con, plugin_data *p, lua_State *L) { + UNUSED(p); /** * get the environment of the function */ @@ -623,6 +692,9 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu lua_pushinteger(L, MAGNET_RESTART_REQUEST); lua_setfield(L, -2, "RESTART_REQUEST"); + lua_pushcfunction(L, magnet_stat); /* (sp += 1) */ + lua_setfield(L, -2, "stat"); /* -1 is the env we want to set (sp -= 1) */ + lua_setfield(L, -2, "lighty"); /* lighty.* (sp -= 1) */ lua_newtable(L); /* the meta-table for the new env (sp += 1) */ |