chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.73k stars 1.2k forks source link

[socket] `basic_stream_socket::non_blocking` not taken into account in `connect` #1337

Open timblechmann opened 11 months ago

timblechmann commented 11 months ago

i'm not sure if it's a bug or a feature, but when setting a socket to non_blocking calling connect may still block. this is especially an issue on windows where connect to localhost on a socket without listener will block for a second instead of failing directly

it seems that sync_connect ( https://github.com/chriskohlhoff/asio/blob/1f8d154829b902dbc45a651587c6c6df948358e8/asio/include/asio/detail/impl/socket_ops.ipp#L509) does not handle the user_set_non_blocking state, where all other socket operations take this flag into account. (e.g. https://github.com/chriskohlhoff/asio/blob/1f8d154829b902dbc45a651587c6c6df948358e8/asio/include/asio/detail/impl/socket_ops.ipp#L1119-L1123)