Skip to content

The tcp socket release function failed often with operation_not_supported on Windows #1614

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

Open
lingyphone opened this issue Apr 4, 2025 · 0 comments

Comments

@lingyphone
Copy link

lingyphone commented Apr 4, 2025

I have a legacy across-platform app, which uses another socket library for the network communication. Since code bases are huge, it may not be able to be rewritten completely with asio.

But I want to change at least the thread model of the app by using asio async_wait functions for the event driven thread model. I have tried the stream_posix_descriptor and works great on the macOS. It takes over the socket fd from current socket library, and assign to an asio stream_posix_descriptor for async_wait, and then release the fd, and current socket library read/write bytes on socket without block. It fits for all kinds of sockets, server_socket for accept, stream_socket for send/receive, even datagram_socket amazingly.

But luck does not come to Windows, firstly the posix_descriptor seems excluded from all Windows platform apps in some purpose, I could tell from the ASIO_HAS_POSIX_STREAM_DESCRIPTOR definition. What is Windows equivalent asio wait-able object ?

And secondly, the ip::tcp::stream_socket accepted from an ip::tcp::acceptor often return failure in the release function with ec of "operation_not_supported", and then socket operations (send/recv) are failed on it when the socket remain as open and connected. The problem comes from below after NtSetInformationFile windows API call. I have not yet found a client stream socket has the similar issue yet.

socket_type win_iocp_socket_service_base::release(
  .... 
  ....
  HANDLE sock_as_handle = reinterpret_cast<HANDLE>(impl.socket_);
  ULONG_PTR iosb[2] = { 0, 0 };
  void* info[2] = { 0, 0 };
  if (fn(sock_as_handle, iosb, &info, sizeof(info),
        61 /* FileReplaceCompletionInformation */))
  {
    ec = asio::error::operation_not_supported;
    return invalid_socket;
  }

Anyone has any clue and how to workaround with this? I am using the latest stable release version of Asio version 1.30.2 .

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

No branches or pull requests

1 participant