Skip to content
Snippets Groups Projects
Commit 32b7b507 authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

The async_client should now be thread-safe.

Rev: lib/modules/Protocols.pmod/DNS.pmod:1.12
parent ff6e4baa
No related branches found
No related tags found
No related merge requests found
...@@ -436,6 +436,10 @@ class async_client ...@@ -436,6 +436,10 @@ class async_client
inherit spider.dumUDP : udp; inherit spider.dumUDP : udp;
int id; int id;
#if constant(thread_create)
object lock = Thread.Mutex();
#endif /* constant(thread_create) */
class Request class Request
{ {
string req; string req;
...@@ -478,18 +482,28 @@ class async_client ...@@ -478,18 +482,28 @@ class async_client
function(string,mapping,mixed...:void) callback, function(string,mapping,mixed...:void) callback,
mixed ... args) mixed ... args)
{ {
#if constant(thread_create)
object key = lock->lock();
#endif /* constant(thread_create) */
id++; id++;
id&=65535; id&=65535;
string req=low_mkquery(id,domain,cl,type); int lid = id;
#if constant(thread_create)
key = 0;
#endif /* constant(thread_create) */
if(requests[id]) if(requests[lid])
throw(({"Cannot find an empty request slot.\n",backtrace()})); throw(({"Cannot find an empty request slot.\n",backtrace()}));
string req=low_mkquery(lid,domain,cl,type);
object r=Request(); object r=Request();
r->req=req; r->req=req;
r->domain=domain; r->domain=domain;
r->callback=callback; r->callback=callback;
r->args=args; r->args=args;
requests[id]=r; requests[lid]=r;
udp::send(nameservers[0],53,r->req); udp::send(nameservers[0],53,r->req);
call_out(retry,5,r,1); call_out(retry,5,r,1);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment