0
votes

I've a boost asio socket. after handshaking phase is over on my custom protocol. I want to take out the socket's native handle from io_service and put it in my own epoll based loop running on a different thread.

So after reading the last message of handshaking phase I am not invoking boost::asio::async_read. But taking the native handle and adding it to my own epoll loop.

But On the client side I get Broken Pipe Error.

I've tried to delay the client before it tries to write, but even when I delay several seconds It gets Broken Pipe. But in that delayed time there is supposed to be another reader on server side, which is the epoll loop.

void hc::common::connection::handle_read(hc::common::connection::state s, const boost::system::error_code& error, std::size_t bytes){
  hook_read(error, bytes);
  if(!error){
    switch(s){
      case header:
        _packet.parse_header();
        ............
        break;
      case body:
        bool keep_reading = available(); // virtual << here it returns false by the overridden method
        _packet.clear();
        if(keep_reading){
            boost::asio::async_read(_socket, 
                boost::asio::buffer(_packet.data(), hc::common::packet::header_length),
                boost::asio::transfer_at_least(hc::common::packet::header_length),
                boost::bind(&hc::common::connection::handle_read, shared_from_this(), header, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
        }
        break;
    }
  }
}
1
Your prose description isn't spectacularly clear. You could enhance it by adding code (mock the epoll library). Do you keep io_service and socket/pipe object alive?sehe
Note that you could use asio::null_buffers to take an advantage of the asio proactor, but perform actual i/o on a native socket using another library.Igor R.
Yes io_service, socket are alive. I cannot just copy paste, because its hard to create a miniature version. What I observe is that in epoll_wait loop I get event triggered, but its EPOLLOUT and only once. no EPOLLIN is captured on that epoll loop.Neel Basu
I too did not find the description clear. Adding code, even a mock up, would help. It is unclear what the server and client are doing, but the error likely indicates the server closed the socket. Can you please show the lifetime of the Boost.Asio I/O objects on the server and how the socket is being migrated?Tanner Sansbury

1 Answers

0
votes

This is a design flaw in asio, it is too restricted. OS does not have such enforcement that a socket can only belong to one monitor, but the library enforce this. The proactor does not allow an OS socket handle to be detached from one socket than attach to another socket object. This is definitely infeasible.