Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 643f8f6

Browse files
committed
Add setsockopt...SO_REUSEADDR to avoid stupid waiting when killing and
restarting the server.
1 parent ccb5ec6 commit 643f8f6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Demo/pysvr/pysvr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ main_thread(int port)
111111
exit(1);
112112
}
113113

114+
#ifdef SO_REUSEADDR
115+
i = 1;
116+
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof i);
117+
#endif
118+
114119
memset((char *)&addr, '\0', sizeof addr);
115120
addr.sin_family = AF_INET;
116121
addr.sin_port = htons(port);
@@ -214,7 +219,6 @@ init_python()
214219
if (gtstate)
215220
return;
216221
Py_Initialize(); /* Initialize the interpreter */
217-
Py_Initialize(); /* Initialize the interpreter */
218222
PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */
219223
gtstate = PyEval_SaveThread(); /* Release the thread state */
220224
}

0 commit comments

Comments
 (0)