chmichael 12 Posted January 7, 2023 (edited) Hello, Can somebody implement the Synced functions of WSocket.DnsLookup and also TWDNSQuery ? (with timeout too) Thank you Edited January 8, 2023 by chmichael Share this post Link to post
FPiette 385 Posted January 8, 2023 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
Angus Robertson 577 Posted January 8, 2023 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
chmichael 12 Posted January 8, 2023 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
chmichael 12 Posted January 8, 2023 (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 January 8, 2023 by chmichael Share this post Link to post
FPiette 385 Posted January 8, 2023 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). 1 Share this post Link to post
Angus Robertson 577 Posted January 8, 2023 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 1 Share this post Link to post
Fr0sT.Brutal 900 Posted January 9, 2023 start async repeat check if async finished until timeout elapsed Share this post Link to post
aehimself 399 Posted January 14, 2023 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
Fr0sT.Brutal 900 Posted January 16, 2023 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
chmichael 12 Posted January 16, 2023 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
Fr0sT.Brutal 900 Posted January 16, 2023 By manually pumping messages, getting only those which were sent to socket control handle. 1 Share this post Link to post
FPiette 385 Posted January 17, 2023 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. 1 Share this post Link to post
aehimself 399 Posted January 17, 2023 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
Fr0sT.Brutal 900 Posted January 18, 2023 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