#include <boost/system/error_code.hpp> #include <boost/asio.hpp> #include <iostream> #include <string> int main() { boost::system::error_code ec; std::string hostname = boost::asio::ip::host_name(ec); std::cout << ec.value() << std::endl; } 下载源代码 Boost...
boost::system::error_code is the most basic class in Boost.System; it represents operating system-specific errors. Because operating systems typically enumerate errors, boost::system::error_code saves an error code in a variable of type int. 1. error_code include <boost/system/error_code.hpp...
void handler1(const boost::system::error_code &ec) { std::cout << "5 s." << std::endl; } void handler2(const boost::system::error_code &ec) { std::cout << "5 s." << std::endl; } boost::asio::io_service io_service; void run() { io_service.run(); } int main() ...
u detail/impl/task_io_service.ipp 具体实现文件 u 队列中的任务类型为opertioan,原型其实是typedef task_io_service_operation operation,其实现文件在detail/task_io_service_operation.hpp中,当队列中的任务被执行时,就是task_io_service_operation:: complete被调用的时候。 Io_servie::Post方法的实现 Post向...
const NetworkMessage& msg, std::string other_name); void handleConnect(const boost::system::error_code& error, std::shared_ptr<boost::asio::ip::tcp::socket> socket, std::string name); void handleHandshakeWrite(const boost::system::error_code& error, std::shared_ptr<DConnection> conn)...
5.I/O执行上下文将操作产生的任何错误转换为asio::error_code类型的对象。error_code可以与特定的值进行比较,或者作为布尔值进行比较(如果结果为假,则表示没有发生错误)。然后将结果转发回I/O对象。 6.如果操作失败,I/O对象会抛出一个asio::system_error类型的异常。如果初始化操作的代码被写成: ...
#include <boost/asio.hpp> #include <fstream> #include <iostream> using boost::system::error_code; using boost::asio::ip::tcp; struct Session : std::enable_shared_from_this<Session> { Session(boost::asio::io_context& io, uint16_t port) : m_socket(io) { m_socket.connect({{}, ...
hpp> #include <boost/bind/bind.hpp> class IPCServer { public: IPCServer(); ~IPCServer(); bool run(); private: void accept_handler(const boost::system::error_code& ec, boost::shared_ptr<boost::asio::ip::tcp::socket> sock); bool accept(); void write_handler(const boost::system::...
#include <iostream> #include <string> #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/smart_ptr.hpp> using namespace boost :: asio ; using boost :: system :: error_code ; using ip :: tcp ; struct CHelloWorld_Service { CHelloWorld_Service (io_service &iosev )...
voidTcpClient::closeSocket(){socket_.close();}voidTcpClient::connect(){socket_.async_connect(ep_,[this](boost::system::error_code ec){if(!ec){isConnected=true;async_read();std::cout<<"connect "<<ep_.address()<<":"<<ep_.port()<<" success"<<endl;}else{std::cout<<"connect "...