EDIT: It looks like this is not my code, but the build environment. This is good and bad, because now I know that the code is fine, but I don’t know how to debug the environment. Any suggestions here? Keep in mind that I do not have administrator rights on this computer.
I'm stuck trying to make code simple under FreeBSD. This is a call async_acceptfrom Boost 1.64 asio that is not behaving. The same code works fine under Windows, but under FreeBSD it accepts a client connection (the connection call on the client side succeeds), but never calls its handler. Not even sure how to approach this. (Please note that unlike other related issues, I call io_service.run()). Please, help.
Standalone code that shows the problem:
#include <iostream>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
namespace asio = boost::asio;
namespace ph = asio::placeholders;
namespace sys = boost::system;
using asio::ip::tcp;
static void accept_handler(const sys::error_code& error)
{
if (error)
std::cout << "failed to connected to server" << std::endl;
else
std::cout << "connected to server" << std::endl;
}
int main(int argc, char* argv[])
{
if (argc < 3)
{
std::cerr << "Usage: accept_test <port> <1 for async and 0 for sync accept>" << std::endl;
return 1;
}
asio::io_service io_service;
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), atoi(argv[1])));
std::cout << "waiting for server connection ";
tcp::socket sock(io_service);
if (argv[2][0] == '1')
{
std::cout << "using async accept..." << std::endl;
acceptor.async_accept(sock, boost::bind(&accept_handler, ph::error));
}
else
{
std::cout << "using sync accept..." << std::endl;
sys::error_code error;
acceptor.accept(sock, error);
if (error)
std::cout << "failed to connected to server" << std::endl;
else
std::cout << "connected to server" << std::endl;
}
io_service.run();
return 0;
}
source
share