Skip to content

Commit ecfc88e

Browse files
committed
Moving out TCP_NODELAY setting from connection constructor.
Moving it to start() instead of the constructor, removing reliance on exceptions. Fixes cpp-netlib#5 .
1 parent bf60c4e commit ecfc88e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

boost/network/protocol/http/connection.hpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ namespace boost { namespace network { namespace http {
4545
, socket_(service_)
4646
, wrapper_(service_)
4747
{
48-
try {
49-
socket_.set_option(tcp::no_delay(true)); // Don't delay writing
50-
} catch (system::system_error & e) {
51-
handler_.log(e.what());
52-
}
5348
}
5449

5550
tcp::socket & socket() {
@@ -62,6 +57,9 @@ namespace boost { namespace network { namespace http {
6257
// and then pass that request object to the
6358
// handler_ instance.
6459
//
60+
boost::system::error_code option_error;
61+
socket_.set_option(tcp::no_delay(true), option_error);
62+
if (option_error) handler_.log(system::system_error(option_error).what());
6563
socket_.async_read_some(
6664
boost::asio::buffer(buffer_),
6765
wrapper_.wrap(

libs/network/test/hello_world.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,26 @@ namespace http = boost::network::http;
1616
using boost::assign::list_of;
1717
using boost::lexical_cast;
1818
using std::string;
19+
using std::cerr;
20+
using std::endl;
1921

2022
struct hello_world;
2123
typedef http::server<hello_world> server;
2224

2325
struct hello_world {
26+
2427
void operator()(server::request const & request, server::response & response) {
2528
response = server::response::stock_reply(server::response::ok, "Hello, World!");
2629
assert(response.status == server::response::ok);
2730
assert(response.headers.size() == 2);
2831
assert(response.content == "Hello, World!");
2932
}
30-
void log(...) {
31-
// do nothing
33+
34+
void log(string const & data) {
35+
cerr << data << endl;
36+
abort();
3237
}
38+
3339
};
3440

3541
int main(int argc, char * argv[]) {
@@ -38,3 +44,4 @@ int main(int argc, char * argv[]) {
3844
server_.run();
3945
return EXIT_SUCCESS;
4046
}
47+

0 commit comments

Comments
 (0)