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

There should be a way to non-destructively disassociate a native handle from a basic_socket #70

Closed
acmorrow opened this issue Jun 15, 2015 · 3 comments

Comments

@acmorrow
Copy link

I'm working with a somewhat complex system and trying to re-write one subsystem to use ASIO without rewriting other subsystem, yet. The subsystem under re-write does not open connections: that is handled by a separate connection pooling subsystem. This is no problem when constructing a stream_socket, because of the stream socket constructor that consumes a native_handle_type, so I can just use the descriptor that I get back from the pool subsystem.

However, after the re-written subsystem has completed its activity, it is expected to hand back the still open socket to the pooling subsystem. This requires that I sever the connection between the stream_socket object and the native handle, so that when the stream_socket object is destroyed, the handle remains valid.

I cannot see a way to accomplish this in ASIO as of the ASIO 1-11-0 API. The ability to temporarily and non-destructively associate existing sockets with ASIO types would make it much easier to incrementally integrate ASIO with existing network libraries while migrating fully to ASIO.

Apologies if I have overlooked a mechanism for doing this in the existing code.

@acmorrow
Copy link
Author

@chriskohlhoff FYI I'd be happy to write a PR for this feature if you are supportive of it. If not (or, worse, if I've missed some obvious existing way to sever the connection between a basic_socket and the underlying native handle), please let me know so I can start working on a different strategy.

@chriskohlhoff
Copy link
Owner

This is not supported because it cannot be portably implemented. Specifically, on Windows a socket is associated to an I/O completion port and cannot be disassociated.

If you are only targeting POSIX-based systems then perhaps you can stick the descriptor into a posix::stream_descriptor instead? This class does provide a release() member function.

@acmorrow
Copy link
Author

@chriskohlhoff I see... that makes sense. I will need to support Windows, so it looks like I will need to find another approach. I appreciate you taking the time to explain.

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

2 participants