Add a new version of tcp_socket::connect_to() that allows you to set the source port
(working, but not yet useful because we'll need to set SO_REUSEADDR)
This commit is contained in:
parent
d27be6851b
commit
2e5fdf952c
3 changed files with 15 additions and 6 deletions
|
|
@ -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 )
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ namespace fc {
|
|||
}
|
||||
void error_handler( const promise<void>::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 )
|
||||
|
|
|
|||
|
|
@ -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()) );
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue