Avoid multiple statements on one line
This commit is contained in:
parent
9140ab7a7d
commit
b9194bf175
|
|
@ -34,9 +34,11 @@ class WebSocketEcho(WebSockifyRequestHandler):
|
||||||
while True:
|
while True:
|
||||||
wlist = []
|
wlist = []
|
||||||
|
|
||||||
if cqueue or c_pend: wlist.append(self.request)
|
if cqueue or c_pend:
|
||||||
|
wlist.append(self.request)
|
||||||
ins, outs, excepts = select.select(rlist, wlist, [], 1)
|
ins, outs, excepts = select.select(rlist, wlist, [], 1)
|
||||||
if excepts: raise Exception("Socket exception")
|
if excepts:
|
||||||
|
raise Exception("Socket exception")
|
||||||
|
|
||||||
if self.request in outs:
|
if self.request in outs:
|
||||||
# Send queued target data to the client
|
# Send queued target data to the client
|
||||||
|
|
@ -65,7 +67,8 @@ if __name__ == '__main__':
|
||||||
(opts, args) = parser.parse_args()
|
(opts, args) = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if len(args) != 1: raise ValueError
|
if len(args) != 1:
|
||||||
|
raise ValueError
|
||||||
opts.listen_port = int(args[0])
|
opts.listen_port = int(args[0])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
parser.error("Invalid arguments")
|
parser.error("Invalid arguments")
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,13 @@ def send(msg):
|
||||||
except WebSocketWantReadError:
|
except WebSocketWantReadError:
|
||||||
msg = ''
|
msg = ''
|
||||||
ins, outs, excepts = select.select([sock], [], [])
|
ins, outs, excepts = select.select([sock], [], [])
|
||||||
if excepts: raise Exception("Socket exception")
|
if excepts:
|
||||||
|
raise Exception("Socket exception")
|
||||||
except WebSocketWantWriteError:
|
except WebSocketWantWriteError:
|
||||||
msg = ''
|
msg = ''
|
||||||
ins, outs, excepts = select.select([], [sock], [])
|
ins, outs, excepts = select.select([], [sock], [])
|
||||||
if excepts: raise Exception("Socket exception")
|
if excepts:
|
||||||
|
raise Exception("Socket exception")
|
||||||
|
|
||||||
|
|
||||||
def read():
|
def read():
|
||||||
|
|
@ -44,10 +46,12 @@ def read():
|
||||||
return sock.recvmsg()
|
return sock.recvmsg()
|
||||||
except WebSocketWantReadError:
|
except WebSocketWantReadError:
|
||||||
ins, outs, excepts = select.select([sock], [], [])
|
ins, outs, excepts = select.select([sock], [], [])
|
||||||
if excepts: raise Exception("Socket exception")
|
if excepts:
|
||||||
|
raise Exception("Socket exception")
|
||||||
except WebSocketWantWriteError:
|
except WebSocketWantWriteError:
|
||||||
ins, outs, excepts = select.select([], [sock], [])
|
ins, outs, excepts = select.select([], [sock], [])
|
||||||
if excepts: raise Exception("Socket exception")
|
if excepts:
|
||||||
|
raise Exception("Socket exception")
|
||||||
|
|
||||||
|
|
||||||
counter = 1
|
counter = 1
|
||||||
|
|
@ -59,7 +63,8 @@ while True:
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
ins, outs, excepts = select.select([sock], [], [], 1.0)
|
ins, outs, excepts = select.select([sock], [], [], 1.0)
|
||||||
if excepts: raise Exception("Socket exception")
|
if excepts:
|
||||||
|
raise Exception("Socket exception")
|
||||||
|
|
||||||
if ins == []:
|
if ins == []:
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,8 @@ class WebSocketLoad(WebSockifyRequestHandler):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
ins, outs, excepts = select.select(socks, socks, socks, 1)
|
ins, outs, excepts = select.select(socks, socks, socks, 1)
|
||||||
if excepts: raise Exception("Socket exception")
|
if excepts:
|
||||||
|
raise Exception("Socket exception")
|
||||||
|
|
||||||
if client in ins:
|
if client in ins:
|
||||||
frames, closed = self.recv_frames()
|
frames, closed = self.recv_frames()
|
||||||
|
|
@ -148,10 +149,12 @@ if __name__ == '__main__':
|
||||||
(opts, args) = parser.parse_args()
|
(opts, args) = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if len(args) != 1: raise ValueError
|
if len(args) != 1:
|
||||||
|
raise ValueError
|
||||||
opts.listen_port = int(args[0])
|
opts.listen_port = int(args[0])
|
||||||
|
|
||||||
if len(args) not in [1, 2]: raise ValueError
|
if len(args) not in [1, 2]:
|
||||||
|
raise ValueError
|
||||||
opts.listen_port = int(args[0])
|
opts.listen_port = int(args[0])
|
||||||
if len(args) == 2:
|
if len(args) == 2:
|
||||||
opts.delay = int(args[1])
|
opts.delay = int(args[1])
|
||||||
|
|
|
||||||
|
|
@ -201,8 +201,10 @@ Traffic Legend:
|
||||||
self.heartbeat = now + self.server.heartbeat
|
self.heartbeat = now + self.server.heartbeat
|
||||||
self.send_ping()
|
self.send_ping()
|
||||||
|
|
||||||
if tqueue: wlist.append(target)
|
if tqueue:
|
||||||
if cqueue or c_pend: wlist.append(self.request)
|
wlist.append(target)
|
||||||
|
if cqueue or c_pend:
|
||||||
|
wlist.append(self.request)
|
||||||
try:
|
try:
|
||||||
ins, outs, excepts = select.select(rlist, wlist, [], 1)
|
ins, outs, excepts = select.select(rlist, wlist, [], 1)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|
@ -217,7 +219,8 @@ Traffic Legend:
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if excepts: raise Exception("Socket exception")
|
if excepts:
|
||||||
|
raise Exception("Socket exception")
|
||||||
|
|
||||||
if self.request in outs:
|
if self.request in outs:
|
||||||
# Send queued target data to the client
|
# Send queued target data to the client
|
||||||
|
|
|
||||||
|
|
@ -528,9 +528,11 @@ class WebSockifyServer():
|
||||||
os.setuid(os.getuid()) # relinquish elevations
|
os.setuid(os.getuid()) # relinquish elevations
|
||||||
|
|
||||||
# Double fork to daemonize
|
# Double fork to daemonize
|
||||||
if os.fork() > 0: os._exit(0) # Parent exits
|
if os.fork() > 0: # Parent exits
|
||||||
os.setsid() # Obtain new process group
|
os._exit(0)
|
||||||
if os.fork() > 0: os._exit(0) # Parent exits
|
os.setsid() # Obtain new process group
|
||||||
|
if os.fork() > 0: # Parent exits
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
# Signal handling
|
# Signal handling
|
||||||
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
||||||
|
|
@ -538,14 +540,16 @@ class WebSockifyServer():
|
||||||
|
|
||||||
# Close open files
|
# Close open files
|
||||||
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
||||||
if maxfd == resource.RLIM_INFINITY: maxfd = 256
|
if maxfd == resource.RLIM_INFINITY:
|
||||||
|
maxfd = 256
|
||||||
for fd in reversed(range(maxfd)):
|
for fd in reversed(range(maxfd)):
|
||||||
try:
|
try:
|
||||||
if fd not in keepfd:
|
if fd not in keepfd:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
except OSError:
|
except OSError:
|
||||||
_, exc, _ = sys.exc_info()
|
_, exc, _ = sys.exc_info()
|
||||||
if exc.errno != errno.EBADF: raise
|
if exc.errno != errno.EBADF:
|
||||||
|
raise
|
||||||
|
|
||||||
# Redirect I/O to /dev/null
|
# Redirect I/O to /dev/null
|
||||||
os.dup2(os.open(os.devnull, os.O_RDWR), sys.stdin.fileno())
|
os.dup2(os.open(os.devnull, os.O_RDWR), sys.stdin.fileno())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue