2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-22 09:57:15 +01:00

Let the forked processes drop closed connections immediately - prefork

This commit is contained in:
Thomas Nagy 2015-02-17 17:10:47 +01:00
parent 9d37801661
commit 68a1bab004
No known key found for this signature in database
GPG Key ID: 67A565EDFDF90E64
2 changed files with 14 additions and 13 deletions

View File

@ -64,14 +64,13 @@ def safe_compare(x, y):
re_valid_query = re.compile('^[a-zA-Z0-9_, ]+$')
class req(SocketServer.StreamRequestHandler):
def handle(self):
while 1:
try:
self.process_command()
except KeyboardInterrupt:
break
except Exception as e:
print(e)
break
try:
while self.process_command():
pass
except KeyboardInterrupt:
return
except Exception as e:
print(e)
def send_response(self, ret, out, err, exc):
if out or err or exc:
@ -91,7 +90,7 @@ class req(SocketServer.StreamRequestHandler):
def process_command(self):
query = self.rfile.read(HEADER_SIZE)
if not query:
return
return None
#print(len(query))
assert(len(query) == HEADER_SIZE)
if sys.hexversion > 0x3000000:
@ -102,7 +101,7 @@ class req(SocketServer.StreamRequestHandler):
if not safe_compare(key, SHARED_KEY):
print('%r %r' % (key, SHARED_KEY))
self.send_response(-1, '', '', 'Invalid key given!')
return
return 'meh'
query = query[:-20]
#print "%r" % query
@ -118,6 +117,7 @@ class req(SocketServer.StreamRequestHandler):
raise ValueError('Exit')
else:
raise ValueError('Invalid query %r' % query)
return 'ok'
def run_command(self, query):

View File

@ -63,7 +63,7 @@ if 1:
def process_command(conn):
query = conn.recv(HEADER_SIZE)
if not query:
return
return None
#print(len(query))
assert(len(query) == HEADER_SIZE)
if sys.hexversion > 0x3000000:
@ -82,6 +82,7 @@ if 1:
raise ValueError('Exit')
else:
raise ValueError('Invalid query %r' % query)
return 'ok'
def run_command(conn, query):
@ -157,8 +158,8 @@ if 1:
# write to child_socket only
try:
while 1:
process_command(child_socket)
while process_command(child_socket):
pass
except KeyboardInterrupt:
sys.exit(2)
else: