Ticket #3900 (closed Feature Requests: fixed)
Request for support of "release" member function or assign without ownership transfer to asio socket
|Reported by:||artyomtnk@…||Owned by:||chris_kohlhoff|
|Milestone:||To Be Determined||Component:||asio|
boost::asio socket has assign member function allowing to transfer native socket to the asio socket. However, there is no option to release such handler or assign without ownership transfer.
Please add one of these options.
Rationale: null_buffer allow easy integration of 3rd part libraries to ASIO main loop for reactor style operations. However, today it is impossible to use it with 3rd part libraries that do not transfer on the socket ownership.
Let's assume I have 3rd part library that gives me a file descriptor to put it in select loop for asynchronous operations.
If I assign file descriptor to the socket, I would not be able to destroy socket object because it would close the connection. and I accidentally may close other valid socket.
Thread A -------- foo f=foo_open() // fd=4 sock.assign(foo_native(f)); ... foo_close(f); // fd = 4 closed Thread B --------- some_fd = open() // some_fd = 4 Thread A -------- ~sock() /// fd=4 closed!!!! thread B can't work
Can you please provide one (or both) of the following APIs:
// Transfer socket ownership to user and reset socket object. native_type release(); // Attach an existing native socket to the socket // (assign do not transfer ownership) void attach(const protocol_type & protocol, const native_type & native_socket); boost::system::error_code attach( const protocol_type & protocol, const native_type & native_socket, boost::system::error_code & ec);
- Milestone changed from Boost 1.43.0 to To Be Determined
comment:11 Changed 3 years ago by chris_kohlhoff
- Status changed from new to closed
- Resolution set to fixed
comment:13 Changed 11 months ago by countforall@…
- Status changed from closed to reopened
- Resolution fixed deleted