Is there a way that allows using an already connected socket in ASIO?
Trying to send one request; ip::tcp::socket::assign
gives randomly 2 different segfaults at 2 different places. One is before calling the callback (on op_queue_acess::next
) and other is after the callback (on boost::asio::detail::task_io_service_operation::complete
(func_ is equal to 0 and tries to be executed)). So I guess it does not work with connected sockets.
Edit:
The case is, I have a connected native descriptor (actually a socket underlying under another library) and I want to assign it to a new, empty ip::tcp::socket so that I can be notified when the socket is read
ready (using the socket::async_read_some
with null buffers) and use the library in a non-blocking way.
Sample code follows as:
class C
{
ip::tcp::socket socket_;
const char connection_info_[] = "...";
TPLibrary tp_;
void start()
{
.
.
tp_.connect(connection_info);
socket_.assign(ip::tcp::v4(), tp_.nativeSocket());
}
}
Then using async_read on this socket gives the said seg fault, sometimes its after calling callback, sometimes before.
EDIT: Now I have removed everything and only the tcp::socket and assigning to the socket left but still boost gives segfaults. Is it because io_service is on a dynamically loaded library and socket is in another dynamically loaded library with a reference to io_service on the main library?