Skip to content

Instantly share code, notes, and snippets.

@nishidy
Last active April 29, 2019 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishidy/d9d2c133308a5a7fba302ae9e06bdb92 to your computer and use it in GitHub Desktop.
Save nishidy/d9d2c133308a5a7fba302ae9e06bdb92 to your computer and use it in GitHub Desktop.
TCP_DEFER_ACCEPT test program for server (python)
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