-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,8 +128,11 @@ ::receive(Socket::endpoint_type const & endpoint) | |
this->_start_deadline(source, error); | ||
|
||
this->_socket = std::make_shared<Socket>(this->_service); | ||
boost::asio::ip::tcp::acceptor acceptor(this->_service, endpoint); | ||
acceptor.async_accept( | ||
this->_acceptor = std::make_shared<boost::asio::ip::tcp::acceptor>( | ||
this->_service, endpoint); | ||
boost::asio::socket_base::reuse_address option(true); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lamyj
Author
Owner
|
||
this->_acceptor->set_option(option); | ||
this->_acceptor->async_accept( | ||
*this->_socket, | ||
[&source,&error](boost::system::error_code const & e) | ||
{ | ||
|
@@ -139,19 +142,25 @@ ::receive(Socket::endpoint_type const & endpoint) | |
); | ||
|
||
this->_run(source, error); | ||
|
||
this->_acceptor = nullptr; | ||
} | ||
|
||
void | ||
Transport | ||
::close() | ||
{ | ||
if(!this->is_open()) | ||
if(this->_acceptor && this->_acceptor->is_open()) | ||
{ | ||
throw Exception("Not connected"); | ||
this->_acceptor->close(); | ||
this->_acceptor = nullptr; | ||
} | ||
if(this->is_open()) | ||
{ | ||
this->_socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both); | ||
this->_socket->close(); | ||
this->_socket = nullptr; | ||
} | ||
|
||
this->_socket->close(); | ||
this->_socket = nullptr; | ||
} | ||
|
||
std::string | ||
|
1 comment
on commit 514c8b6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On windows at least, calling shutdown on an opened but not connected socket throws an exception. It occurs in the destructor of dul::Transport, so it crashes the application with no hope of recovery.
It happened when I tried to connect using the wrong host port. Association::associate threw, I catched it, then the Association was freed and down the line the socket threw.
I am not sure how to protect against these kind of network errors, but we really ought to solidify odil in this area.
I just had the funniest bug... I was only receiving half the connections I was creating on the other end.
It appeared I launched my program twice, and with the option reuse_address to true, each program was sharing the same listening port.
Not sure it is a good idea?