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;
}
}
}
io_service
and socket/pipe object alive? – seheepoll_wait
loop I get event triggered, but itsEPOLLOUT
and only once. noEPOLLIN
is captured on that epoll loop. – Neel Basu