Pull websockify: zombie reap, ignore unready clients.

This commit is contained in:
Joel Martin 2011-01-31 12:13:30 -06:00
parent 40f281ebbd
commit ec2b614037
2 changed files with 20 additions and 5 deletions

View File

@ -213,7 +213,11 @@ Connection: Upgrade\r
stype = "" stype = ""
# Peek, but don't read the data ready = select.select([sock], [], [], 3)[0]
if not ready:
raise self.EClose("ignoring socket not ready")
# Peek, but do not read the data so that we have a opportunity
# to SSL wrap the socket first
handshake = sock.recv(1024, socket.MSG_PEEK) handshake = sock.recv(1024, socket.MSG_PEEK)
#self.msg("Handshake [%s]" % repr(handshake)) #self.msg("Handshake [%s]" % repr(handshake))
@ -308,10 +312,18 @@ Connection: Upgrade\r
def poll(self): def poll(self):
""" Run periodically while waiting for connections. """ """ Run periodically while waiting for connections. """
self.msg("Running poll()") #self.vmsg("Running poll()")
pass
def top_SIGCHLD(self, sig, stack):
# Reap zombies after calling child SIGCHLD handler
self.do_SIGCHLD(sig, stack)
self.vmsg("Got SIGCHLD, reaping zombies")
os.waitpid(-1, os.WNOHANG)
def do_SIGCHLD(self, sig, stack): def do_SIGCHLD(self, sig, stack):
self.vmsg("Got SIGCHLD, ignoring") pass
def do_SIGINT(self, sig, stack): def do_SIGINT(self, sig, stack):
self.msg("Got SIGINT, exiting") self.msg("Got SIGINT, exiting")
@ -340,7 +352,7 @@ Connection: Upgrade\r
self.started() # Some things need to happen after daemonizing self.started() # Some things need to happen after daemonizing
# Reep zombies # Reep zombies
signal.signal(signal.SIGCHLD, self.do_SIGCHLD) signal.signal(signal.SIGCHLD, self.top_SIGCHLD)
signal.signal(signal.SIGINT, self.do_SIGINT) signal.signal(signal.SIGINT, self.do_SIGINT)
while True: while True:

View File

@ -160,7 +160,10 @@ Traffic Legend:
try: try:
self.do_proxy(client, tsock) self.do_proxy(client, tsock)
except: except:
if tsock: tsock.close() if tsock:
tsock.close()
self.vmsg("%s:%s: Target closed" %(
self.target_host, self.target_port))
if self.rec: if self.rec:
self.rec.write("'EOF']\n") self.rec.write("'EOF']\n")
self.rec.close() self.rec.close()