我创建了一个TCP客户端,它有一个boost asio tcp套接字,并进行异步读取:
class TCPClient { public: TCPClient(boost::asio::io_service& io_service) : socket_(io_service) { // Connect [...] // Asynchronous read socket_.async_read_some(boost::asio::buffer(buffer, buffer.size()), boost::bind(&TCPClient::handlerRead, this, placeholders::error, placeholders::bytes_transferred)); ~TCPClient() {} void handlerRead(const boost::system::error_code& ec, uint32_t bytes) { if (!ec) { // process [...] socket_.async_read_some( boost::asio::buffer(buffer, buffer.size()), boost::bind(&TCPClient::handlerRead, this, placeholders::error, placeholders::bytes_transferred)); int getSocketFd() { return socket_.native_handle(); private: boost::asio::tcp::socket socket_;