Skip to content

Commit

Permalink
rec: Add getRecursorThreadId() to Lua, identifying the current thread
Browse files Browse the repository at this point in the history
(cherry picked from commit b401545)
  • Loading branch information
rgacogne committed Dec 12, 2016
1 parent 1dde8cc commit bb6bd6e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/markdown/recursor/scripting.md
Expand Up @@ -379,6 +379,9 @@ entry. Entries are listed in the following table:
Public Suffix List. In general it will tell you the 'registered domain' for a given Public Suffix List. In general it will tell you the 'registered domain' for a given
name. name.


`getRecursorThreadId()` returns an unsigned integer identifying the thread
handling the current request.

## DNS64 ## DNS64
The `getFakeAAAARecords` and `getFakePTRRecords` followupFunctions can be used The `getFakeAAAARecords` and `getFakePTRRecords` followupFunctions can be used
to implement DNS64. See [DNS64 support in the PowerDNS Recursor](dns64.md) for to implement DNS64. See [DNS64 support in the PowerDNS Recursor](dns64.md) for
Expand Down
6 changes: 5 additions & 1 deletion pdns/lua-recursor4.cc
Expand Up @@ -531,7 +531,11 @@ RecursorLua4::RecursorLua4(const std::string& fname)
d_lw->registerFunction("incBy", &DynMetric::incBy); d_lw->registerFunction("incBy", &DynMetric::incBy);
d_lw->registerFunction("set", &DynMetric::set); d_lw->registerFunction("set", &DynMetric::set);
d_lw->registerFunction("get", &DynMetric::get); d_lw->registerFunction("get", &DynMetric::get);


d_lw->writeFunction("getRecursorThreadId", []() {
return getRecursorThreadId();
});



ifstream ifs(fname); ifstream ifs(fname);
if(!ifs) { if(!ifs) {
Expand Down
1 change: 1 addition & 0 deletions pdns/lua-recursor4.hh
Expand Up @@ -31,6 +31,7 @@
#endif #endif


string GenUDPQueryResponse(const ComboAddress& dest, const string& query); string GenUDPQueryResponse(const ComboAddress& dest, const string& query);
unsigned int getRecursorThreadId();


class LuaContext; class LuaContext;


Expand Down
6 changes: 5 additions & 1 deletion pdns/pdns_recursor.cc
Expand Up @@ -91,7 +91,7 @@ extern SortList g_sortlist;
#endif #endif


__thread FDMultiplexer* t_fdm; __thread FDMultiplexer* t_fdm;
__thread unsigned int t_id; static __thread unsigned int t_id;
unsigned int g_maxTCPPerClient; unsigned int g_maxTCPPerClient;
unsigned int g_networkTimeoutMsec; unsigned int g_networkTimeoutMsec;
uint64_t g_latencyStatSize; uint64_t g_latencyStatSize;
Expand Down Expand Up @@ -214,6 +214,10 @@ ArgvMap &arg()
return theArg; return theArg;
} }


unsigned int getRecursorThreadId()
{
return t_id;
}


void handleTCPClientWritable(int fd, FDMultiplexer::funcparam_t& var); void handleTCPClientWritable(int fd, FDMultiplexer::funcparam_t& var);


Expand Down

0 comments on commit bb6bd6e

Please sign in to comment.