Hi All,
Got a problem restarting my server:
bind: Address already in use
I start it like:
Code:
srv.sin_addr.s_addr = INADDR_ANY;
srv.sin_port = htons( port);
srv.sin_family = AF_INET;
sock_opt = 1;
if(setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(void *)&sock_opt,sizeof(sock_opt)) == -1)
{
perror("setsockopt(SO_REUSEADDR)");
close(s);
return 3;
}
if(bind(s,(struct sockaddr *)&srv,sizeof(srv)) == -1)
{
perror("bind");
close(s);
return 4;
}
if(listen(s,3) == -1)
{
perror("listen");
close(s);
return 5;
}
So it should be reusing the socket.
Had a look in nestat and:
Code:
tcp 25 0 localhost:5580 localhost:40353 CLOSE_WAIT
tcp 48 0 localhost:5580 localhost:40352 CLOSE_WAIT
tcp 25 0 localhost:5580 localhost:40361 CLOSE_WAIT
tcp 48 0 localhost:5580 localhost:40360 CLOSE_WAIT
Connections in CLOSE_WAIT state.
Any ideas how I can get round this?
Cheers, rotis23