Commit 90ba9418 authored by Jonathan Williamson's avatar Jonathan Williamson

Fix "bind: Address already in use" error if restart before socket is free

parent 11090500
...@@ -892,13 +892,17 @@ int main (int argc, char **argv) { ...@@ -892,13 +892,17 @@ int main (int argc, char **argv) {
if (port > 0) { if (port > 0) {
struct sockaddr_in serv_addr; struct sockaddr_in serv_addr;
int yes = 1;
sfd = socket (AF_INET, SOCK_STREAM, 0); sfd = socket (AF_INET, SOCK_STREAM, 0);
if (sfd < 0) { if (sfd < 0) {
perror ("socket"); perror ("socket");
exit(1); exit(1);
} }
if(setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) < 0) {
perror("setsockopt");
exit(1);
}
memset (&serv_addr, 0, sizeof (serv_addr)); memset (&serv_addr, 0, sizeof (serv_addr));
serv_addr.sin_family = AF_INET; serv_addr.sin_family = AF_INET;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment