diff --git a/include/fc/network/tcp_socket.hpp b/include/fc/network/tcp_socket.hpp index e66c1a5..a6affb3 100644 --- a/include/fc/network/tcp_socket.hpp +++ b/include/fc/network/tcp_socket.hpp @@ -11,7 +11,8 @@ namespace fc { tcp_socket(); ~tcp_socket(); - void connect_to( const fc::ip::endpoint& e ); + void connect_to( const fc::ip::endpoint& remote_endpoint ); + void connect_to( const fc::ip::endpoint& remote_endpoint, const fc::ip::endpoint& local_endpoint ); fc::ip::endpoint remote_endpoint()const; void get( char& c ) diff --git a/src/asio.cpp b/src/asio.cpp index 6bcebd8..d8db2ce 100644 --- a/src/asio.cpp +++ b/src/asio.cpp @@ -35,7 +35,8 @@ namespace fc { } void error_handler( const promise::ptr& p, const boost::system::error_code& ec ) { - if( !ec ) p->set_value(); + if( !ec ) + p->set_value(); else { if( ec == boost::asio::error::operation_aborted ) diff --git a/src/network/tcp_socket.cpp b/src/network/tcp_socket.cpp index 74297b6..e71d759 100644 --- a/src/network/tcp_socket.cpp +++ b/src/network/tcp_socket.cpp @@ -10,7 +10,7 @@ namespace fc { class tcp_socket::impl { public: - impl():_sock( fc::asio::default_io_service() ){ } + impl():_sock( fc::asio::default_io_service() ){} ~impl(){ if( _sock.is_open() ) _sock.close(); } @@ -53,8 +53,15 @@ namespace fc { return r; } - void tcp_socket::connect_to( const fc::ip::endpoint& e ) { - fc::asio::tcp::connect(my->_sock, fc::asio::tcp::endpoint( boost::asio::ip::address_v4(e.get_address()), e.port() ) ); + void tcp_socket::connect_to( const fc::ip::endpoint& remote_endpoint ) { + fc::asio::tcp::connect(my->_sock, fc::asio::tcp::endpoint( boost::asio::ip::address_v4(remote_endpoint.get_address()), remote_endpoint.port() ) ); + } + + void tcp_socket::connect_to( const fc::ip::endpoint& remote_endpoint, const fc::ip::endpoint& local_endpoint ) { + my->_sock = boost::asio::ip::tcp::socket(fc::asio::default_io_service(), + boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4(local_endpoint.get_address()), + local_endpoint.port())); + fc::asio::tcp::connect(my->_sock, fc::asio::tcp::endpoint( boost::asio::ip::address_v4(remote_endpoint.get_address()), remote_endpoint.port() ) ); } class tcp_server::impl { @@ -69,7 +76,7 @@ namespace fc { try { _accept.close(); } - catch ( boost::system::system_error& e ) + catch ( boost::system::system_error& ) { wlog( "unexpected exception ${e}", ("e", fc::except_str()) ); }