c++ - Address already in use with boost asio acceptor -


i wrote server listening incomming tcp connections , clients connecting it. when shut down server , restart on same port, error message eaddrinuse when calling bind(...) (error code: 98 on linux). happens though setting option reuse socket.

the error not happen time, seems happens more when clients connected server , sending data while shuts down. guess problem there still pending connections while server shut down (related topic: https://stackoverflow.com/questions/41602/how-to-forcibly-close-a-socket-in-time-wait).

on server side, using boost::asio::ip::tcp::acceptor. initialize option "reuse_address" (see http://beta.boost.org/doc/libs/1_38_0/doc/html/boost_asio/reference/basic_socket_acceptor.html). here code snippet:

using boost::asio::ip::tcp; acceptor acceptor::acceptor(io_service); endpoint ep(ip::tcp::v4(), port); acceptor.open(ep.protocol()); acceptor.set_option(acceptor::reuse_address(true)); acceptor.bind(ep); acceptor.listen(); 

the acceptor closed with:

acceptor.close(); 

i tried using acceptor.cancel() before that, had same effect. when error occurred, cannot restart server on same port quite time. restarting network helps, not permanent solution.

what missing?

any appreciated! :)

these comment question.


does server fork child processes? also, sure socket in time_wait state? might want grab netstat -ap output when happens


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -