PDA

View Full Version : setsockopt issues



Elkvis
06-22-2011, 09:39 AM
I have a multi-process linux server application that receives a connection via accept() and forks to handle the requests on that new connection. I'm calling setsockopt(ClientSocket, SOL_SOCKET, SO_REUSEADDR....) on the new sockets, and from time to time, this will completely lock up my server and make it stop passing the connections off to the handler. the new connections are accepted, and the fork occurs, but the child process just stops on the setsockopt() line.

my question is: do I need to set that socket option on the new connection's socket, or just on the listening socket (which I also do)?

MK27
06-22-2011, 11:24 AM
my question is: do I need to set that socket option on the new connection's socket, or just on the listening socket (which I also do)?

It does not make sense to use SO_REUSEADDR on the client sockets because they do not have bind() called on them, and are already connected.

WRT your problem, that might even be the cause of it.

Elkvis
06-22-2011, 01:53 PM
that makes sense. it seems to be working better since I commented out that section of code, so I think it's fixed, but I guess we'll see what happens.

MK27
06-22-2011, 02:04 PM
it seems to be working better but I guess we'll see what happens.

Writing network code sometimes makes me think of trying to throw tennis balls into a hopper that might be a little bit too small, from twenty yards in pitch darkness, having never once seen the area in the light, with your thumb taped to your forefinger and a mysterious wind gusting intermittently from any direction.