Update tcp_socket listen on single endpoint

This commit is contained in:
Daniel Larimer 2014-02-14 20:32:23 -05:00
parent 9392ca2afe
commit a80164645f
2 changed files with 15 additions and 6 deletions

View file

@ -55,6 +55,7 @@ namespace fc {
void close(); void close();
void accept( tcp_socket& s ); void accept( tcp_socket& s );
void listen( uint16_t port ); void listen( uint16_t port );
void listen( const fc::ip::endpoint& ep );
uint16_t get_port()const; uint16_t get_port()const;
private: private:

View file

@ -59,9 +59,12 @@ namespace fc {
class tcp_server::impl { class tcp_server::impl {
public: public:
impl(uint16_t port): impl(uint16_t port)
_accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port) ){ :_accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port) ){}
}
impl(const fc::ip::endpoint& ep )
:_accept( fc::asio::default_io_service(), boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4( ep.get_address()), ep.port()) ){}
~impl(){ ~impl(){
try { try {
_accept.close(); _accept.close();
@ -100,6 +103,11 @@ namespace fc {
if( my ) delete my; if( my ) delete my;
my = new impl(port); my = new impl(port);
} }
void tcp_server::listen( const fc::ip::endpoint& ep )
{
if( my ) delete my;
my = new impl(ep);
}
uint16_t tcp_server::get_port()const uint16_t tcp_server::get_port()const
{ {