diff --git a/src/Network/TcpServer.cpp b/src/Network/TcpServer.cpp index 57bff6362..00a6a4363 100644 --- a/src/Network/TcpServer.cpp +++ b/src/Network/TcpServer.cpp @@ -93,7 +93,6 @@ void TcpServer::cloneFrom(const TcpServer &that) { _main_server = false; _on_create_socket = that._on_create_socket; _session_alloc = that._session_alloc; - _socket->cloneSocket(*(that._socket)); weak_ptr weak_self = std::static_pointer_cast(shared_from_this()); _timer = std::make_shared(2.0f, [weak_self]() -> bool { auto strong_self = weak_self.lock(); @@ -105,6 +104,7 @@ void TcpServer::cloneFrom(const TcpServer &that) { }, _poller); this->mINI::operator=(that); _parent = static_pointer_cast(const_cast(that).shared_from_this()); + _socket->cloneSocket(*(that._socket)); } // 接收到客户端连接请求 diff --git a/src/Network/UdpServer.cpp b/src/Network/UdpServer.cpp index 5ece12c57..50ca26de1 100644 --- a/src/Network/UdpServer.cpp +++ b/src/Network/UdpServer.cpp @@ -117,11 +117,14 @@ void UdpServer::cloneFrom(const UdpServer &that) { throw std::invalid_argument("UdpServer::cloneFrom other with null socket"); } setupEvent(); + _cloned = true; // clone callbacks _on_create_socket = that._on_create_socket; _session_alloc = that._session_alloc; _session_mutex = that._session_mutex; _session_map = that._session_map; + // clone properties + this->mINI::operator=(that); // clone udp socket #if 0 _socket->cloneSocket(*(that._socket)); @@ -129,9 +132,6 @@ void UdpServer::cloneFrom(const UdpServer &that) { // 实验发现cloneSocket方式虽然可以节省fd资源,但是在某些系统上线程漂移问题更严重 _socket->bindUdpSock(that._socket->get_local_port(), that._socket->get_local_ip()); #endif - // clone properties - this->mINI::operator=(that); - _cloned = true; } void UdpServer::onRead(const Buffer::Ptr &buf, sockaddr *addr, int addr_len) {