简体   繁体   English

套接字从boost :: asio :: io_service迁移到另一个epoll循环

[英]socket migration from boost::asio::io_service to another epoll loop

I've a boost asio socket. 我有一个升压的asio插槽。 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. 我想从io_service中取出套接字的本机句柄,并将其放入在其他线程上运行的基于我自己的epoll的循环中。

So after reading the last message of handshaking phase I am not invoking boost::asio::async_read . 因此,在阅读了握手阶段的最后一条消息之后,我没有调用boost::asio::async_read But taking the native handle and adding it to my own epoll loop. 但是要使用本机句柄并将其添加到我自己的epoll循环中。

But On the client side I get Broken Pipe Error. 但是在客户端,我会收到“ Broken Pipe错误。

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. 但是在那延迟的时间内,应该在服务器端有另一个阅读器,这就是epoll循环。

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;
    }
  }
}

This is a design flaw in asio, it is too restricted. 这是asio中的设计缺陷,它太受限制了。 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. Proactor不允许将OS套接字句柄与一个套接字分离,而不能附加到另一个套接字对象。 This is definitely infeasible. 这绝对是不可行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM