2018-12-09 16:30:31 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Opens sockets until they run out.
|
2022-11-23 03:18:39 +03:00
|
|
|
import socket
|
2018-12-09 17:10:06 +03:00
|
|
|
from time import time
|
2018-12-09 16:30:31 +03:00
|
|
|
|
|
|
|
def main():
|
|
|
|
request = b'GET /darkhttpd.c HTTP/1.0\r\n'
|
|
|
|
socks = []
|
|
|
|
print('Trying to connect...')
|
|
|
|
first = True
|
|
|
|
while True:
|
|
|
|
try:
|
2018-12-09 17:10:06 +03:00
|
|
|
t0 = time(); s = socket.socket()
|
|
|
|
t1 = time(); s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
|
|
|
t2 = time(); s.connect(("", 8080))
|
|
|
|
t3 = time(); s.send(request)
|
|
|
|
t4 = time(); socks.append(s)
|
|
|
|
t5 = time()
|
|
|
|
print('%d sockets open, %f sock, %f setsockopt, %f connect, %f send, %f append' % (
|
|
|
|
len(socks), t1-t0, t2-t1, t3-t2, t4-t3, t5-t4))
|
2018-12-09 16:30:31 +03:00
|
|
|
except Exception as e:
|
|
|
|
if first:
|
|
|
|
print(e)
|
|
|
|
first = False
|
|
|
|
pass
|
|
|
|
|
|
|
|
if __name__ == '__main__': main()
|
|
|
|
|
|
|
|
# vim:set sw=2 ts=2 sts=2 et tw=80:
|