SDL_net and SO_REUSEADDR (second try)

Hmm, thanks for the reply, but I guess I wasn’t phrasing my question

I have written a very simple server. After a server crash, I cannot
restart the server for ~30 seconds. I know (approximately) why, and I
hacked SDL_net
to fix the problem. The real question is whether or not the fix is
portable and clean.

After an unnegotiated shutdown, sockets take some time to expire. The
socket guys provided a workaround for this: the option SO_REUSEADDR.
However, SDLnet won’t let me pass socket options. I made the following
change to SDLnetTCP.c, and I can now restart the server without having
to twiddle my thumbs
for 30 seconds.

At about line 175 or so of SDLnetTCP.c (new code with > brackets):

	/* Bind the socket for listening */
  if(setsockopt(sock->channel, SOL_SOCKET, SO_REUSEADDR, 
  	      (char*)&opt, sizeof(opt))) {     
		SDLNet_SetError("Couldn't set socket options");
                  goto error_return;
	if ( bind(sock->channel, (struct sockaddr *)&sock_addr,
			sizeof(sock_addr)) == SOCKET_ERROR ) {
		SDLNet_SetError("Couldn't bind to local port");
		goto error_return;

I know there are some reasons why this particular option might be a bad
but it makes debugging the server much much easier! Can I propose
adding the
ability to pass some sort of socket options to SDL_net? (Of course,
from my
perspective the problem is fixed; I’ll just keep running my hacked
of the library :slight_smile: