I have a simple boost::asio::ip::tcp::acceptor
which does almost nothing - it accepts connections in an infinite loop. I then have a number of connectors running at the same time trying to connect...
pSocket->async_connect(endpoint,
[=](boost::system::error_code error)
{
if(!error)
{
boost::asio::ip::tcp::no_delay noDelay(true);
pSocket->set_option(noDelay, error);
assert(!error);
std::cout << error.message() << '\n'; // "An invalid argument was supplied"
}
});
Everything is running in infinite loops and I'm running 2 clients and 1 server, all loopback connections. After a while (hundreds of successful connects and disconnects) when setting the no_delay
option on the connected socket I get the error An invalid argument was supplied
.
Under what conditions can setting an option on a socket cause this error? Has anyone seen this before, and know why it's happening and/or a way to fix it?
Update:
If I change the set set_option
to something like...
do
{
pSocket->set_option(noDelay, error);
} while(error);
...it will succeed - usually on the second try after it fails.