Jump to content
chmichael

DNS Query & Lookup Synced

Recommended Posts

Posted (edited)

Hello,

  Can somebody implement the Synced functions of WSocket.DnsLookup and also TWDNSQuery ? (with timeout too)

Thank you

Edited by chmichael

Share this post


Link to post

If you are looking for that, you are probably on the wrong track using ICS. It is much better to design your application using asynchronous operation only.

Share this post


Link to post

ICS deliberately does not offer sync version of the low level Winsock functions, only high level protocols like HTTP and FTP. 

 

There is a blocking version of DnsLookup, but no timeout is possible since the OS function waits up to 30 seconds or more for DNS servers to respond to queries, So you need to implement your own abort on timeout.  Or use the TDnsQuery component

 

Angus

 

Share this post


Link to post
6 hours ago, FPiette said:

If you are looking for that, you are probably on the wrong track using ICS. It is much better to design your application using asynchronous operation only.

Well the TSSLSmtpCli has blocking functions which they work nicely.  eg, OpenSync; MailSync;

 

Share this post


Link to post
Posted (edited)
4 hours ago, Angus Robertson said:

ICS deliberately does not offer sync version of the low level Winsock functions, only high level protocols like HTTP and FTP. 

  

There is a blocking version of DnsLookup, but no timeout is possible since the OS function waits up to 30 seconds or more for DNS servers to respond to queries, So you need to implement your own abort on timeout.  Or use the TDnsQuery component

  

Angus 

 

Where is the blocking function ?

Also wouldn't be nice to have a timeout for that ?

Edited by chmichael

Share this post


Link to post
1 hour ago, chmichael said:

Well the TSSLSmtpCli has blocking functions which they work nicely.  eg, OpenSync; MailSync;

Well, those are old functions that I was convinced to write. I assure you there are side effects that can be annoying (If you click on a button while a "Sync" function is working, the button event handler is called and could cause reentrancy issues if you do take care of it) if you don't master how Windows messaging system work. I keep the old "Sync" functions to preserve compatibility with old code peoples are still using (You may know that ICS is 26 years old and most if not all code written by then is still working unchanged).

  • Like 1

Share this post


Link to post
Quote

Where is the blocking function ?

Also wouldn't be nice to have a timeout for that ? 

Reverse DNS is WSocketResolveIp, forward DNS is WSocketResolveHost, blocking means no timeout is possible, unless you mess with registry settings that affect every other application on the PC. 

 

Angus

  • Like 1

Share this post


Link to post
On 1/9/2023 at 11:20 AM, Fr0sT.Brutal said:

start async

repeat

  check if async finished

until timeout elapsed

And then? 🙂 TerminateThread? 🙂

Share this post


Link to post
On 1/14/2023 at 9:44 PM, aehimself said:

And then? 🙂 TerminateThread? 🙂

Why? Just break the loop and return error code

Share this post


Link to post
On 1/9/2023 at 12:20 PM, Fr0sT.Brutal said:

start async

repeat

  check if async finished

until timeout elapsed

The question is how to check it without using application.processmessages ?

Share this post


Link to post

By manually pumping messages, getting only those which were sent to socket control handle.

  • Like 1

Share this post


Link to post
On 1/16/2023 at 2:34 PM, chmichael said:

The question is how to check it without using application.processmessages ? 

If you are using ICS within a worker thread, you have to create a message pump. See the sample applications delivered with ICS there are several showing how to use a message pump which is not Application.ProcessMessages.

  • Like 1

Share this post


Link to post
8 hours ago, FPiette said:

you have to create a message pump.

TIcsWndControl exposes ProcessMessage, ProcessMessages, MessagePump and MessageLoop for all scenarios. You guys were prepared, there's no need to create, only to use!

Share this post


Link to post

Another option (pseudocode):
 

ev := CreateEvent(..)

thr := TThread.CreateAnon(

  begin

     getaddrinfo(...)

     SetEvent(ev)

  end);

thr.Start;

WaitForSingleObject(ev, TIMEOUT)

TerminateThread(thr.Handle)

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×