<snip>
> Is this an RPC client-server program?
> If it is, it's done intentionally so that any messages that may still
> float around have a destination to rest in peace.
No RPC (if I understand what that means correctly), just 'regular' socket
programming.
> Use "select()" socket utility.
> It may mean a little extra programming, but it is really rewarding.
Not sure how select() would help here. In this case the "server" side just do
really simple stuff, basically read and write to socket descriptor. It could
be that when server is interupted, there is still I/O that makes it not
immediately release the port. Are you saying using select() to clean up ?
You are right, you don't need select() if you just want to clean up. You
might want to consider it since it gracefully manages resources when
there is some network error/interrupt. Look at the chat server example:
http://beej.us/guide/bgnet/output/html/advanced.html#select
This is how you clean up the socket.
// lose the pesky "address already in use" error message
if (setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) ==
-1)
{
perror("setsockopt");
exit(1);
}