Groovy
Groovy

Reputation: 516

Using boost::asio and native socket calls within same process

Are there any known issues in using Boost::asio and native calls like accept() (both TCP sockets) within same process (different threads). I am on Debian and using C++ language. My observation is that accept() behaves inconsistently.

On a particular instance of running the process, Clients are able to connect smoothly. Any number of clients connect smoothly.

On another instance of running the process, accept call just fails saying "Invalid argument" when a client connects. Such an error is supposed to come when the socket is not properly configured as listening socket. Once this error, same error comes for all the clients trying to connect. Only workaround is to run the process again and hope that next time it works fine.

More observations:- - When some more descriptors are opened for some files, problem tends to go away - If I remove the boost::asio code, accept works absolutely fine

Limitations: Cannot share my code

Upvotes: 0

Views: 551

Answers (2)

Groovy
Groovy

Reputation: 516

I spawned two different threads. No problem after that.

Upvotes: 0

Sam Miller
Sam Miller

Reputation: 24174

There are no issues using Boost.Asio with system calls such as accept(), I've done it in several projects without problems. Based on your description, it sounds like undefined behavior to me. I would guess you are leaking descriptors, double close()-ing descriptors, or not checking return codes where appropriate. If you are unable to post code, use a tool like valgrind to aid your debugging efforts.

Upvotes: 0

Related Questions