Last active
April 29, 2019 02:45
-
-
Save nishidy/d9d2c133308a5a7fba302ae9e06bdb92 to your computer and use it in GitHub Desktop.
TCP_DEFER_ACCEPT test program for server (python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
QUEUELIMIT = 5 | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
s.bind(('',8080)) | |
s.listen(QUEUELIMIT) | |
s.setsockopt(socket.SOL_TCP, socket.TCP_DEFER_ACCEPT, 1) | |
while True: | |
conn, addr = s.accept() | |
print("accept() unblocked.") | |
if conn: | |
while True: | |
data = conn.recv(1024) | |
if not data: | |
break | |
print(data) | |
conn.send(b"HTTP/1.1 200 OK") | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment