You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by hu...@apache.org on 2013/04/19 10:46:29 UTC
svn commit: r1469744 - in /httpd/httpd/trunk: docs/manual/mod/mod_lua.xml
modules/lua/lua_request.c modules/lua/lua_request.h
Author: humbedooh
Date: Fri Apr 19 08:46:28 2013
New Revision: 1469744
URL: http://svn.apache.org/r1469744
Log:
Remove lua_ap_banner, as it's no longer being used.
Add ivm_get/ivm_set for Inter-VM data transfer. This allows multiple VMs across a process to share data without having to resort to external databases or filesystems. This is a work in progress, and I have yet to work out a proper way of resetting a variable without causing a memory leak (this could be done by allocating a new pool for each object, but I'm trying to see if there's a more efficient way). Comments, ideas etc are most welcome.
Modified:
httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
httpd/httpd/trunk/modules/lua/lua_request.c
httpd/httpd/trunk/modules/lua/lua_request.h
Modified: httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_lua.xml?rev=1469744&r1=1469743&r2=1469744&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_lua.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_lua.xml Fri Apr 19 08:46:28 2013
@@ -889,6 +889,15 @@ r:dbacquire(dbType[, dbParams]) -- Acqui
-- See '<a href="#databases">Database connectivity</a>' for details.
</highlight>
+<highlight language="lua">
+r:ivm_set("key", value) -- Set an Inter-VM variable to hold a specific value.
+ -- These values persist even though the VM is gone or not being used,
+ -- and so should only be used if MaxConnectionsPerChild is > 0
+ -- Values can be numbers, strings and booleans.
+
+r:ivm_get("key") -- Fetches a variable set by ivm_set. Returns the contents of the variable
+ -- if it exists or nil if no such variable exists.
+</highlight>
</section>
Modified: httpd/httpd/trunk/modules/lua/lua_request.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1469744&r1=1469743&r2=1469744&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_request.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_request.c Fri Apr 19 08:46:28 2013
@@ -15,6 +15,11 @@
* limitations under the License.
*/
+#include <lua.h>
+
+
+#include <apr_pools.h>
+
#include "mod_lua.h"
#include "util_script.h"
#include "lua_apr.h"
@@ -33,6 +38,7 @@ typedef char *(*req_field_string_f) (req
typedef int (*req_field_int_f) (request_rec * r);
typedef apr_table_t *(*req_field_apr_table_f) (request_rec * r);
+
void ap_lua_rstack_dump(lua_State *L, request_rec *r, const char *msg)
{
int i;
@@ -823,16 +829,6 @@ static int lua_apr_sha1(lua_State *L)
}
-
-/*
- * lua_ap_banner; r:banner() - Returns the current server banner
- */
-static int lua_ap_banner(lua_State *L)
-{
- lua_pushstring(L, ap_get_server_banner());
- return 1;
-}
-
/*
* lua_ap_mpm_query; r:mpm_query(info) - Queries for MPM info
*/
@@ -1665,6 +1661,49 @@ static int req_debug(lua_State *L)
return req_log_at(L, APLOG_DEBUG);
}
+static int lua_ivm_get(lua_State *L) {
+ const char *key, *raw_key;
+ lua_ivm_object *object = NULL;
+ request_rec *r = ap_lua_check_request_rec(L, 1);
+ key = luaL_checkstring(L, 2);
+ raw_key = apr_pstrcat(r->pool, "lua_ivm_", key, NULL);
+ apr_pool_userdata_get((void **)&object, raw_key, r->server->process->pool);
+ if (object) {
+ if (object->type == LUA_TBOOLEAN) lua_pushboolean(L, object->number);
+ else if (object->type == LUA_TBOOLEAN) lua_pushboolean(L, object->number);
+ else if (object->type == LUA_TNUMBER) lua_pushnumber(L, object->number);
+ else if (object->type == LUA_TSTRING) lua_pushlstring(L, object->string, object->size);
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
+
+static int lua_ivm_set(lua_State *L) {
+ const char *key, *raw_key;
+ const char *value = NULL;
+ lua_ivm_object *object = NULL;
+ request_rec *r = ap_lua_check_request_rec(L, 1);
+ key = luaL_checkstring(L, 2);
+ luaL_checkany(L, 3);
+ raw_key = apr_pstrcat(r->pool, "lua_ivm_", key, NULL);
+
+ /* This will require MaxConnectionsPerChild to be > 0, since it's
+ * essentially leaking memory as values are being overridden */
+ object = apr_pcalloc(r->server->process->pool, sizeof(lua_ivm_object));
+ object->type = lua_type(L, 3);
+ if (object->type == LUA_TNUMBER) object->number = lua_tonumber(L, 3);
+ else if (object->type == LUA_TBOOLEAN) object->number = lua_tonumber(L, 3);
+ else if (object->type == LUA_TSTRING) {
+ value = lua_tolstring(L, 3, &object->size);
+ object->string = apr_pstrmemdup(r->server->process->pool, value, object->size);
+ }
+ apr_pool_userdata_set(object, raw_key, NULL, r->server->process->pool);
+ return 0;
+}
+
#define APLUA_REQ_TRACE(lev) static int req_trace##lev(lua_State *L) \
{ \
return req_log_at(L, APLOG_TRACE##lev); \
@@ -1770,6 +1809,8 @@ static const char* lua_ap_get_server_nam
return name ? name : "localhost";
}
+
+
static const struct luaL_Reg server_methods[] = {
{NULL, NULL}
};
@@ -1996,6 +2037,10 @@ AP_LUA_DECLARE(void) ap_lua_load_request
makefun(&lua_ap_state_query, APL_REQ_FUNTYPE_LUACFUN, p));
apr_hash_set(dispatch, "get_server_name_for_url", APR_HASH_KEY_STRING,
makefun(&lua_ap_get_server_name_for_url, APL_REQ_FUNTYPE_LUACFUN, p));
+ apr_hash_set(dispatch, "ivm_get", APR_HASH_KEY_STRING,
+ makefun(&lua_ivm_get, APL_REQ_FUNTYPE_LUACFUN, p));
+ apr_hash_set(dispatch, "ivm_set", APR_HASH_KEY_STRING,
+ makefun(&lua_ivm_set, APL_REQ_FUNTYPE_LUACFUN, p));
lua_pushlightuserdata(L, dispatch);
lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
Modified: httpd/httpd/trunk/modules/lua/lua_request.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.h?rev=1469744&r1=1469743&r2=1469744&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_request.h (original)
+++ httpd/httpd/trunk/modules/lua/lua_request.h Fri Apr 19 08:46:28 2013
@@ -37,5 +37,11 @@ typedef struct
int type;
} req_fun_t;
+typedef struct {
+ int type;
+ size_t size;
+ void* string;
+ lua_Number number;
+} lua_ivm_object;
#endif /* !_LUA_REQUEST_H_ */
Re: svn commit: r1469744 - in /httpd/httpd/trunk: docs/manual/mod/mod_lua.xml
modules/lua/lua_request.c modules/lua/lua_request.h
Posted by Guenter Knauf <fu...@apache.org>.
Hi Daniel,
On 19.04.2013 10:46, humbedooh@apache.org wrote:
> Author: humbedooh Date: Fri Apr 19 08:46:28 2013
> New Revision: 1469744
>
> URL: http://svn.apache.org/r1469744
> Log:
> Remove lua_ap_banner, as it's no longer being used.
> Add ivm_get/ivm_set for Inter-VM data
> transfer. This allows multiple VMs across a process to share data
> without having to resort to external databases or filesystems. This
> is a work in progress, and I have yet to work out a proper way of
> resetting a variable without causing a memory leak (this could be
> done by allocating a new pool for each object, but I'm trying to see
> if there's a more efficient way). Comments, ideas etc are most
> welcome.
please, in the future, make 2 separate commits for things like that.
The 1st part is a simple removal of dead code, while the 2nd introduces
a new feature, so they are not related.
thanks, Gün.
Re: svn commit: r1469744 - in /httpd/httpd/trunk: docs/manual/mod/mod_lua.xml
modules/lua/lua_request.c modules/lua/lua_request.h
Posted by Daniel Gruno <ru...@cord.dk>.
On 04/19/2013 11:02 AM, Ruediger Pluem wrote:
>
>
> humbedooh@apache.org wrote:
>> Author: humbedooh
>> Date: Fri Apr 19 08:46:28 2013
>> New Revision: 1469744
>>
>> URL: http://svn.apache.org/r1469744
>> Log:
>> Remove lua_ap_banner, as it's no longer being used.
>> Add ivm_get/ivm_set for Inter-VM data transfer. This allows multiple VMs across a process to share data without having to resort to external databases or filesystems. This is a work in progress, and I have yet to work out a proper way of resetting a variable without causing a memory leak (this could be done by allocating a new pool for each object, but I'm trying to see if there's a more efficient way). Comments, ideas etc are most welcome.
>>
>> Modified:
>> httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
>> httpd/httpd/trunk/modules/lua/lua_request.c
>> httpd/httpd/trunk/modules/lua/lua_request.h
>>
>
>> Modified: httpd/httpd/trunk/modules/lua/lua_request.c
>> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1469744&r1=1469743&r2=1469744&view=diff
>> ==============================================================================
>> --- httpd/httpd/trunk/modules/lua/lua_request.c (original)
>> +++ httpd/httpd/trunk/modules/lua/lua_request.c Fri Apr 19 08:46:28 2013
>
>> @@ -1665,6 +1661,49 @@ static int req_debug(lua_State *L)
>> return req_log_at(L, APLOG_DEBUG);
>> }
>>
>> +static int lua_ivm_get(lua_State *L) {
>> + const char *key, *raw_key;
>> + lua_ivm_object *object = NULL;
>> + request_rec *r = ap_lua_check_request_rec(L, 1);
>> + key = luaL_checkstring(L, 2);
>> + raw_key = apr_pstrcat(r->pool, "lua_ivm_", key, NULL);
>> + apr_pool_userdata_get((void **)&object, raw_key, r->server->process->pool);
>> + if (object) {
>> + if (object->type == LUA_TBOOLEAN) lua_pushboolean(L, object->number);
>> + else if (object->type == LUA_TBOOLEAN) lua_pushboolean(L, object->number);
>
> Isn't that the same condition twice above?
>
>> + else if (object->type == LUA_TNUMBER) lua_pushnumber(L, object->number);
>> + else if (object->type == LUA_TSTRING) lua_pushlstring(L, object->string, object->size);
>> + return 1;
>> + }
>> + else {
>> + return 0;
>> + }
>> +}
>> +
>> +
>
> Regards
>
> Rüdiger
>
you're absolutely right, silly of me :)
I'll fix right away.
With regards,
Daniel.
Re: svn commit: r1469744 - in /httpd/httpd/trunk: docs/manual/mod/mod_lua.xml
modules/lua/lua_request.c modules/lua/lua_request.h
Posted by Ruediger Pluem <rp...@apache.org>.
humbedooh@apache.org wrote:
> Author: humbedooh
> Date: Fri Apr 19 08:46:28 2013
> New Revision: 1469744
>
> URL: http://svn.apache.org/r1469744
> Log:
> Remove lua_ap_banner, as it's no longer being used.
> Add ivm_get/ivm_set for Inter-VM data transfer. This allows multiple VMs across a process to share data without having to resort to external databases or filesystems. This is a work in progress, and I have yet to work out a proper way of resetting a variable without causing a memory leak (this could be done by allocating a new pool for each object, but I'm trying to see if there's a more efficient way). Comments, ideas etc are most welcome.
>
> Modified:
> httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
> httpd/httpd/trunk/modules/lua/lua_request.c
> httpd/httpd/trunk/modules/lua/lua_request.h
>
> Modified: httpd/httpd/trunk/modules/lua/lua_request.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1469744&r1=1469743&r2=1469744&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/lua/lua_request.c (original)
> +++ httpd/httpd/trunk/modules/lua/lua_request.c Fri Apr 19 08:46:28 2013
> @@ -1665,6 +1661,49 @@ static int req_debug(lua_State *L)
> return req_log_at(L, APLOG_DEBUG);
> }
>
> +static int lua_ivm_get(lua_State *L) {
> + const char *key, *raw_key;
> + lua_ivm_object *object = NULL;
> + request_rec *r = ap_lua_check_request_rec(L, 1);
> + key = luaL_checkstring(L, 2);
> + raw_key = apr_pstrcat(r->pool, "lua_ivm_", key, NULL);
> + apr_pool_userdata_get((void **)&object, raw_key, r->server->process->pool);
> + if (object) {
> + if (object->type == LUA_TBOOLEAN) lua_pushboolean(L, object->number);
> + else if (object->type == LUA_TBOOLEAN) lua_pushboolean(L, object->number);
Isn't that the same condition twice above?
> + else if (object->type == LUA_TNUMBER) lua_pushnumber(L, object->number);
> + else if (object->type == LUA_TSTRING) lua_pushlstring(L, object->string, object->size);
> + return 1;
> + }
> + else {
> + return 0;
> + }
> +}
> +
> +
Regards
Rüdiger