diff --git a/changelog.md b/changelog.md index 01b142554f..dd6e580ff2 100644 --- a/changelog.md +++ b/changelog.md @@ -12,7 +12,7 @@ HEAD 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 + TCP socket option. The default for this value has been changed from `true` to `false`. - Feature: Adds the ability to specify a maximum message size. - Feature: Adds `close::status::get_string(...)` method to look up a human @@ -30,8 +30,8 @@ HEAD short reads and quasi-expected socket shutdown related errors will no longer be reported as unclean WebSocket shutdowns to the application. Information about them will remain in the info error channel for debugging purposes. -- Improvement: `start_accept` errors are now reported to the caller either via - an exception or an ec parameter. +- Improvement: `start_accept` and `listen` errors are now reported to the caller + either via an exception or an ec parameter. - Bug: Fix some cases of calls to empty lib::function objects. - Bug: Fix memory leak of connection objects due to cached handlers holding on to reference counted pointers. #310 Thank you otaras for reporting. diff --git a/websocketpp/transport/asio/endpoint.hpp b/websocketpp/transport/asio/endpoint.hpp index 21bb610e57..a7bf8a36f9 100644 --- a/websocketpp/transport/asio/endpoint.hpp +++ b/websocketpp/transport/asio/endpoint.hpp @@ -123,7 +123,7 @@ public: : m_io_service(src.m_io_service) , m_external_io_service(src.m_external_io_service) , m_acceptor(src.m_acceptor) - , m_listen_backlog(0) + , m_listen_backlog(boost::asio::socket_base::max_connections) , m_reuse_addr(src.m_reuse_addr) , m_state(src.m_state) { @@ -145,7 +145,7 @@ public: rhs.m_io_service = NULL; rhs.m_external_io_service = false; rhs.m_acceptor = NULL; - rhs.m_listen_backlog = 0; + rhs.m_listen_backlog = boost::asio::socket_base::max_connections; rhs.m_state = UNINITIALIZED; } return *this; @@ -344,16 +344,25 @@ public: m_alog->write(log::alevel::devel,"asio::listen"); - m_acceptor->open(ep.protocol()); - 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(); - } else { - m_acceptor->listen(m_listen_backlog); + boost::system::error_code bec; + + m_acceptor->open(ep.protocol(),bec); + if (!bec) { + m_acceptor->set_option(boost::asio::socket_base::reuse_address(m_reuse_addr),bec); + } + if (!bec) { + m_acceptor->bind(ep,bec); + } + if (!bec) { + m_acceptor->listen(m_listen_backlog,bec); + } + if (bec) { + log_err(log::elevel::info,"asio listen",bec); + ec = make_error_code(error::pass_through); + } else { + m_state = LISTENING; + ec = lib::error_code(); } - m_state = LISTENING; - ec = lib::error_code(); } /// Set up endpoint for listening manually