websocketpp
websocketpp copied to clipboard
tcp::no_delay leads to Bad file descriptor
The following program attempts to start a server and set the NO_DELAY option on the socket as soon as it has been initialised. This worked with 0.7, but no longer with 0.8.1. Commenting out the s.set_option(option) line makes it work again.
Am I doing this wrong or is this a bug?
#include <websocketpp/server.hpp>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/common/functional.hpp>
typedef websocketpp::server<websocketpp::config::asio> WebsocketServer;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
void on_socket_init(websocketpp::connection_hdl, boost::asio::ip::tcp::socket & s)
{
boost::asio::ip::tcp::no_delay option(true);
s.set_option(option);
}
int main(int, char **)
{
WebsocketServer wserver;
wserver.init_asio();
wserver.set_reuse_addr(true);
wserver.set_socket_init_handler(bind(&on_socket_init, ::_1,::_2));
wserver.listen(0);
wserver.start_accept();
websocketpp::lib::asio::error_code ec;
auto p = wserver.get_local_endpoint(ec);
std::cout << p.port() << std::endl;
}
I am seeing this issue as well. Was working on websocketpp 0.5.1; upgraded to 0.8.1 and it no longer works
I am also experiencing the same issue. My application works without errors when using v0.7.0. When I try to use v0.8.1 instead, I get the error. Commenting out the tcp::no_delay line in my code makes it work, but I would like to set the option. Attached is the relevant gdb stack trace, if that's any help:
#0 0x00007ffff66eae97 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff66ec801 in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff6d41957 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff6d47ab6 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff6d47af1 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff6d47d24 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00005555555871e0 in asio::detail::throw_exception<std::system_error> (e=...) at /usr/include/asio/detail/throw_exception.hpp:42
#7 0x000055555556cd06 in asio::detail::do_throw_error (err=..., location=0x55555563dd77 "set_option") at /usr/include/asio/detail/impl/throw_error.ipp:49
#8 0x000055555556cc39 in asio::detail::throw_error (err=..., location=0x55555563dd77 "set_option") at /usr/include/asio/detail/throw_error.hpp:41
#9 0x000055555558ee7a in asio::basic_socket<asio::ip::tcp, asio::stream_socket_service<asio::ip::tcp> >::set_option<asio::detail::socket_option::boolean<6, 1> > (this=0x555555918ce0, option=...) at /usr/include/asio/basic_socket.hpp:819
Hi Same here. any solution? -Thanks
Any workaround for this issue?
This regression from 0.8.0 has been fixed on the develop branch. The socket_init event handler is the correct place to set socket options like TCP_NODELAY on the already accepted socket.
Hi, why don't you merge the fix into main branch?