Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign TIdTCPClient connect with timeout without extra thread... #466

Closed
gec75 opened this issue Apr 25, 2023 · 1 comment
Closed

Redesign TIdTCPClient connect with timeout without extra thread... #466

gec75 opened this issue Apr 25, 2023 · 1 comment
Labels
Element: I/O Handlers Issues related to TIdIOHandler and descendants Element: Socket Stacks Issues related to OS socket APIs, TIdStack and TIdSocketList descedants, etc Element: TCP Issues related to TCP handling, TIdTCPClient and TIdTCPServer descendants, etc Status: Duplicate Issue is a duplicate of another issue Type: Enhancement Issue is proposing a new feature/enhancement

Comments

@gec75
Copy link

gec75 commented Apr 25, 2023

I have an application where I need a very short connect timeout.
Then I just saw that Indy starts a new thread for this connect ...!?
I took the time to implement a version based on non blocking connect and select... see attached patch.
The idea is to split TIdSocketHandle.Connect into GStack.Connect (which starts an non-blocking connect) and later UpdateBinding.
The code in TIdIOHandlerStack.ConnectClient just starts connect then waits with select (write) and then decides to UpdateBinding or raise exception.
I also added the TIdSocketListWindows.SelectWrite... why was it not yet included??
It's just a prof of concept code, no AntiFreeze and no posix variant.

indy_asyc_connect.patch

@gec75 gec75 changed the title Redesign GStack.Connect without extra thread... Redesign TIdTCPClient.Connect without extra thread... Apr 25, 2023
@gec75 gec75 changed the title Redesign TIdTCPClient.Connect without extra thread... Redesign TIdTCPClient connect with timeout without extra thread... Apr 25, 2023
@rlebeau rlebeau added Status: Duplicate Issue is a duplicate of another issue Type: Enhancement Issue is proposing a new feature/enhancement Element: Socket Stacks Issues related to OS socket APIs, TIdStack and TIdSocketList descedants, etc Element: TCP Issues related to TCP handling, TIdTCPClient and TIdTCPServer descendants, etc labels Apr 25, 2023
@rlebeau
Copy link
Member

rlebeau commented Apr 25, 2023

Duplicate of #3

I have added your patch to that ticket so it is not lost. Might get some useful tidbits from it.

I already have some code written for this feature (ultimately using a non-blocking connect() and handling the timeout via select()/epoll(), similarly to how you suggest, but taking a very different approach to the implementation to lessen changes to the existing interface). That code hasn't been finished or even checked in yet.

Also, not every platform supports non-blocking sockets to begin with, so the connect thread can't be eliminated completely, but certainly avoided whenever possible. The code I have queries the stack if non-blocking is supported, and if so then does the non-blocking connect(), otherwise uses the connect thread as before.

@rlebeau rlebeau added the Element: I/O Handlers Issues related to TIdIOHandler and descendants label Apr 25, 2023
@rlebeau rlebeau closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Element: I/O Handlers Issues related to TIdIOHandler and descendants Element: Socket Stacks Issues related to OS socket APIs, TIdStack and TIdSocketList descedants, etc Element: TCP Issues related to TCP handling, TIdTCPClient and TIdTCPServer descendants, etc Status: Duplicate Issue is a duplicate of another issue Type: Enhancement Issue is proposing a new feature/enhancement
Projects
None yet
Development

No branches or pull requests

2 participants