I’m using Boost ASIO sockets for communicating with some remote devices under linux, but i have a problem when the endpoint is not reachable. First of all, here’s the portion of code that shows this issue:
try {
if(mysocket == NULL)
{
mysocket = new boost::asio::ip::tcp::socket(io_service);
}
mysocket->connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("192.168.0.12"), 1));
printf("connected\n");
return 0;
}
catch (std::exception &e)
{
boost::system::error_code ec;
mysocket->close(ec);
delete mysocket;
mysocket = NULL;
printf("not connected %s\n", e.what());
}
By using this piece of code inside my class I get an increasing number of file descriptors of type eventfd, until all the available fds are used and the application crashes. Is there any problem with the code above? Why boost is not closing the file descriptors? I even delete the socket!
Thanks in advance!
The problem was due to not releasing resources, such as boost sockets. Those sockets left open files, which gradually reached the open file limit in my system, thus trying to open additional files resulted in an error. The actual exception was thrown by the boost UUID generator, which could not open files!