Reputation: 130
The issue I'm having is that asio::async_connect does not invoke its call back handler (in this case foo), even though the connection has already been established on the server end. It's very perplexing to me since async_read / write works as expected.
Here is a simplified example
void foo(const asio::error_code& ec)
{
std::cout << "Foo called" << std::endl;
}
int main()
{
asio::io_service io;
asio::io_service::work work(io);
asio::ip::tcp::socket socket(io);
asio::ip::tcp::endpoint ep(asio::ip::address::from_string("127.0.0.1"), 5454);
socket.async_connect(ep, std::bind(&foo, std::placeholders::_1));
io.run();
return 0;
}
Upvotes: 0
Views: 393
Reputation: 130
The issue was I had two different io_service objects with the same name, and was calling io.run() on the wrong one. The code snippet actually worked when I tested it in a standalone case.
Upvotes: 1