Skip to content
Snippets Groups Projects
Commit 75c66dba authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

optimized

Rev: lib/modules/Protocols.pmod/DNS.pmod:1.23
parent 08bc4e4c
No related branches found
No related tags found
No related merge requests found
...@@ -477,13 +477,8 @@ class async_client ...@@ -477,13 +477,8 @@ class async_client
{ {
inherit client; inherit client;
inherit spider.dumUDP : udp; inherit spider.dumUDP : udp;
int id;
async_client next_client; async_client next_client;
#if constant(thread_create)
static private inherit Thread.Mutex : lock;
#endif /* constant(thread_create) */
class Request class Request
{ {
string req; string req;
...@@ -526,57 +521,11 @@ class async_client ...@@ -526,57 +521,11 @@ class async_client
function(string,mapping,mixed...:void) callback, function(string,mapping,mixed...:void) callback,
mixed ... args) mixed ... args)
{ {
int lid; for(int e=next_client ? 5 : 256;e>=0;e--)
#if constant(thread_create)
object key=lock::lock();
#endif /* constant(thread_create) */
for(int e=next_client ? 5 : 1024;e>=0;e--)
{
id++;
id&=65535;
lid=id;
if(requests[lid])
{
if(time() - requests[lid]->timestamp > GIVE_UP_DELAY)
{
#if constant(thread_create)
// We need to unlock the lock for the remove operation...
destruct(key);
#endif /* constant(thread_create) */
remove(requests[lid]);
#if constant(thread_create)
key=lock::lock();
#endif /* constant(thread_create) */
if(requests[lid]) continue; /* Another thread has stolen lid */
}else{
continue;
}
}
break;
}
if(requests[lid])
{ {
/* We failed miserably to find a request id to use, int lid = random(65536);
* so we create a second UDP port to be able to have more if(!catch { requests[lid]++; })
* requests 'in the air'. /Hubbe
*/
if(!next_client)
{ {
next_client=async_client(nameservers,domains);
next_client->nameservers=nameservers;
next_client->domains=domains;
}
#if constant(thread_create)
key=0;
#endif /* constant(thread_create) */
next_client->do_query(domain, cl, type, callback, @args);
return;
}
string req=low_mkquery(lid,domain,cl,type); string req=low_mkquery(lid,domain,cl,type);
object r=Request(); object r=Request();
...@@ -588,6 +537,18 @@ class async_client ...@@ -588,6 +537,18 @@ class async_client
requests[lid]=r; requests[lid]=r;
udp::send(nameservers[0],53,r->req); udp::send(nameservers[0],53,r->req);
call_out(retry,RETRY_DELAY,r,1); call_out(retry,RETRY_DELAY,r,1);
return;
}
}
/* We failed miserably to find a request id to use,
* so we create a second UDP port to be able to have more
* requests 'in the air'. /Hubbe
*/
if(!next_client)
next_client=async_client(nameservers,domains);
next_client->do_query(domain, cl, type, callback, @args);
} }
static private void rec_data() static private void rec_data()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment