I am testing a Socket class I have written that wraps the Linux socket API.
In a test function I do the following:
- Create a server socket
- bind/listen
- connect from a new socket
- accept on a new socket
- send some data between them with recv and send.
- call shutdown(SHUT_WR) on both sides
- call recv on both sides, and get a 0 return value
- call close on all three sockets
I then immediately repeat these 8 steps again.
I find that intermittantly on the bind
in the second iteration of the steps I get EADDRINUSE.
I was of the impression that it was possible to perform an orderly shutdown in such a fashion that this was avoidable. I am aware of SO_REUSEADDR
- but is it possible to do an orderly shutdown and block until the port is available again?