Skip to content

IOCP - Use ConnectEx in async_connect when available - #9

Closed
VemundH wants to merge 3 commits into
chriskohlhoff:masterfrom
VemundH:feature/ConnectEx
Closed

VemundH wants to merge 3 commits into
chriskohlhoff:masterfrom
VemundH:feature/ConnectEx

Conversation

@VemundH

@VemundH VemundH commented Jan 6, 2014

Copy link
Copy Markdown

async_accept was used as motivation. (E.g. win_iocp_socket_connect_op is based on win_iocp_socket_accept_op)

Implementation details/considerations:

  1. ConnectEx is available starting with Windows XP.
  2. The ConnectEx function pointer must be obtained at run time. The pointer is stored in a static local variable as a potential optimization. The code does not prevent potential race as it does not really matter if multiple threads initialize the static variable (the code is safe).
  3. ConnectEx can only be called with connection-oriented sockets. This is tested run-time, and sockets of type ASIO_OS_DEF(SOCK_STREAM) and ASIO_OS_DEF(SOCK_SEQPACKET) are considered connection-oriented. I did not find a simple solution to making this a compile-time test. (SOCK_RDM is also connection-oriented, but omitted as I could not find ASIO_OS_DEF(SOCK_RDM))
  4. ConnectEx requires a bound socket. The implementation will always call bind. This is OK also in case the socket is already bound (see comment in code).

The code will fall back on using the reactor implementation if the code targets and earlier version of Windows than XP, the socket is not connection-oriented or in case of failure to obtain the ConnectEx function pointer.

A version without the “optimization” in (2) is available in this commit: VemundH@f89c15a

@VemundH

VemundH commented Feb 5, 2014

Copy link
Copy Markdown
Author

The best solution for solving (3) is probably to add something like:

ASIO_STATIC_CONSTANT(bool, connection_oriented = true or false);

to the socket "protocol_type" classes. This is kind of a design decision that should be approved before making changes to the code.

@chriskohlhoff

Copy link
Copy Markdown
Owner

Addressed using a different approach in 9fc74ea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants