bool Socket::Open() { if (out_buffer_.get()) return false; // Store peer address. address_ = ObtainRemoteAddress(); if (address_ == UNKNOWN_NETWORK_ADDRESS) { sLog.outError("bool Socket::Open() address_ == UNKNOWN_NETWORK_ADDRESS!"); return false; } // Hook for the manager. if (!manager_.OnSocketOpen(shared_from_this())) { sLog.outError("if (!manager_.OnSocketOpen(shared_from_this()))"); return false; } closed_ = false; // Allocate buffers. out_buffer_.reset(new NetworkBuffer(outgoing_buffer_size_)); read_buffer_.reset(new NetworkBuffer(protocol::READ_BUFFER_SIZE)); // Start reading data from client StartAsyncRead(); return true; }
void Socket::OnReadComplete(const boost::system::error_code& error, size_t bytes_transferred) { if (error) { OnError(error); return; } if (bytes_transferred > 0) { read_buffer_->Commit(bytes_transferred); if (!ProcessIncomingData()) { CloseSocket(); return; } } StartAsyncRead(); }
bool Socket::Open() { if (out_buffer_.get()) return false; address_ = ObtainRemoteAddress(); if (address_ == UNKNOWN_NETWORK_ADDRESS) return false; if (!manager_.OnSocketOpen(shared_from_this())) return false; closed_ = false; out_buffer_.reset(new NetworkBuffer(outgoing_buffer_size_)); read_buffer_.reset(new NetworkBuffer(protocol::READ_BUFFER_SIZE)); StartAsyncRead(); return true; }
FORCEINLINE void StartSerializeBufferRead() { StartAsyncRead(SerializeBuffer); }
FORCEINLINE void StartStreamBufferRead() { StartAsyncRead(StreamBuffer); }