boost asio对于epoll关闭套接字顺序

其方法定义在

boost::system::error_code reactive_socket_service_base::close(
    reactive_socket_service_base::base_implementation_type& impl,
    boost::system::error_code& ec)
{
  if (is_open(impl))
  {
    BOOST_ASIO_HANDLER_OPERATION(("socket", &impl, "close"));

    reactor_.deregister_descriptor(impl.socket_, impl.reactor_data_,
        (impl.state_ & socket_ops::possible_dup) == 0);
  }

  socket_ops::close(impl.socket_, impl.state_, false, ec);

  // The descriptor is closed by the OS even if close() returns an error.
  //
  // (Actually, POSIX says the state of the descriptor is unspecified. On
  // Linux the descriptor is apparently closed anyway; e.g. see
  //   http://lkml.org/lkml/2005/9/10/129
  // We'll just have to assume that other OSes follow the same behaviour. The
  // known exception is when Windows's closesocket() function fails with
  // WSAEWOULDBLOCK, but this case is handled inside socket_ops::close().
  construct(impl);

  return ec;
}
  • 判断socket是否等于-1,如果不是,则执行下一步
  • 调用epoll_reactor的deregister_descriptor方法,也是调用epoll_ctl(epoll_fd_, EPOLL_CTL_DEL, descriptor, &ev);
  • 调用socket_ops::close 关闭套接字
  • 调用 construct 将socket设置为-1

你可能感兴趣的:(boost,boost)