Adds configurable SO_REUSEADDR option. references #311

This commit is contained in:
Peter Thorson
2014-02-02 18:12:30 -06:00
parent ca97dd1fb8
commit fe85de763e
3 changed files with 27 additions and 1 deletions

View File

@@ -11,6 +11,8 @@ HEAD
- Feature: Adds the ability to pause reading on a connection. Paused connections will not
read more data from their socket, allowing TCP flow control to work without blocking
the main thread.
- Feature: Adds the ability to specify whether or not to use the `SO_REUSEADDR` TCP socket
option. The default for this value has been changed from `true` to `false`.
- Improvement: Open, close, and pong timeouts can be disabled entirely by setting their
duration to 0.
- Improvement: Numerous performance improvements. Including: tuned default

View File

@@ -108,6 +108,7 @@ void run_server(server * s, int port, bool log = false) {
}
s->init_asio();
s->set_reuse_addr(true);
s->listen(port);
s->start_accept();
@@ -124,6 +125,7 @@ void run_client(client & c, std::string uri, bool log = false) {
}
websocketpp::lib::error_code ec;
c.init_asio(ec);
c.set_reuse_addr(true);
BOOST_CHECK(!ec);
client::connection_ptr con = c.get_connection(uri,ec);

View File

@@ -91,6 +91,7 @@ public:
explicit endpoint()
: m_external_io_service(false)
, m_listen_backlog(0)
, m_reuse_addr(false)
, m_state(UNINITIALIZED)
{
//std::cout << "transport::asio::endpoint constructor" << std::endl;
@@ -123,6 +124,7 @@ public:
, m_external_io_service(src.m_external_io_service)
, m_acceptor(src.m_acceptor)
, m_listen_backlog(0)
, m_reuse_addr(src.m_reuse_addr)
, m_state(src.m_state)
{
src.m_io_service = NULL;
@@ -137,6 +139,7 @@ public:
m_external_io_service = rhs.m_external_io_service;
m_acceptor = rhs.m_acceptor;
m_listen_backlog = rhs.m_listen_backlog
m_reuse_addr = rhs.m_reuse_addr;
m_state = rhs.m_state;
rhs.m_io_service = NULL;
@@ -287,6 +290,24 @@ public:
void set_listen_backlog(int backlog) {
m_listen_backlog = backlog;
}
/// Sets whether or not to use the SO_REUSEADDR flag when opening a listening socket
/**
* Specifies whether or not to use the SO_REUSEADDR TCP socket option. What this flag
* does depends on your operating system. Please consult operating system
* documentation for more details.
*
* New values affect future calls to listen only.
*
* The default is false.
*
* @since 0.4.0-alpha1
*
* @param value Whether or not to use the SO_REUSEADDR option
*/
void set_reuse_addr(bool value) {
m_reuse_addr = value;
}
/// Retrieve a reference to the endpoint's io_service
/**
@@ -324,7 +345,7 @@ public:
m_alog->write(log::alevel::devel,"asio::listen");
m_acceptor->open(ep.protocol());
m_acceptor->set_option(boost::asio::socket_base::reuse_address(true));
m_acceptor->set_option(boost::asio::socket_base::reuse_address(m_reuse_addr));
m_acceptor->bind(ep);
if (m_listen_backlog == 0) {
m_acceptor->listen();
@@ -1024,6 +1045,7 @@ private:
// Network constants
int m_listen_backlog;
bool m_reuse_addr;
elog_type* m_elog;
alog_type* m_alog;