diff options
author | dormando <dormando@rydia.net> | 2022-03-01 16:17:34 -0800 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2022-03-01 16:17:34 -0800 |
commit | 31ccfc19fcbe15a5f40c559483c4c95082781ece (patch) | |
tree | 15ef3a2d7bb09ea24cc54a93735bab7a1ecbee35 | |
parent | fa745db8fffe7d13438fe2437bdf8fcb1372bc96 (diff) | |
download | memcached-31ccfc19fcbe15a5f40c559483c4c95082781ece.tar.gz |
proxy: mcp.request(cmd, [val | resp])
mcp.request can now take a response object and internally copy the
value. bit faster than doing it through C.
iterating from here should allow taking a reference to the resp object
and directly pointing to its value, but we need to make resp objects
immutable first.
-rw-r--r-- | proxy_request.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/proxy_request.c b/proxy_request.c index 9aecf5b..f351cc1 100644 --- a/proxy_request.c +++ b/proxy_request.c @@ -525,7 +525,19 @@ int mcplib_request(lua_State *L) { size_t vlen = 0; mcp_parser_t pr = {0}; const char *cmd = luaL_checklstring(L, 1, &len); - const char *val = luaL_optlstring(L, 2, NULL, &vlen); + const char *val = NULL; + int type = lua_type(L, 2); + if (type == LUA_TSTRING) { + val = luaL_optlstring(L, 2, NULL, &vlen); + } else if (type == LUA_TUSERDATA) { + mcp_resp_t *r = luaL_checkudata(L, 2, "mcp.response"); + if (r->buf) { + val = r->buf; + vlen = r->blen; + } else { + // TODO (v2): other response modes unhandled. + } + } // FIXME (v2): if we inline the userdata we can avoid memcpy'ing the parser // structure from the stack? but causes some code duplication. |