-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a UNIX domain socket server that accepts connections and never responds, so that we can test timeouts on the client side.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import socket | ||
import time | ||
import os | ||
|
||
server_address = './uds_socket' | ||
|
||
# Make sure the socket does not already exist | ||
try: | ||
os.unlink(server_address) | ||
except OSError: | ||
if os.path.exists(server_address): | ||
raise | ||
|
||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
print('starting up on {}'.format(server_address)) | ||
sock.bind(server_address) | ||
sock.listen(1) | ||
|
||
while True: | ||
print('\nwaiting for a connection') | ||
|
||
connection, client_address = sock.accept() | ||
connection.settimeout(300) | ||
|
||
try: | ||
print('connected') | ||
connect_time = time.time() | ||
while True: | ||
try: | ||
data = connection.recv(640) | ||
if not data: | ||
print('no data') | ||
break | ||
except socket.timeout as exc: | ||
elapsed_time = int(time.time() - connect_time) | ||
print(f'timeout after {elapsed_time}s on recv') | ||
break | ||
finally: | ||
connection.close() |