Mercurial > cosocket
changeset 25:6fc400fb8b0b
example http server now supports connection keep-alive.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 21 Apr 2009 23:47:55 -0700 |
parents | 1c1bddd319e5 |
children | 4a4b66f5229b |
files | example.py |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/example.py Tue Apr 21 23:15:32 2009 -0700 +++ b/example.py Tue Apr 21 23:47:55 2009 -0700 @@ -3,6 +3,8 @@ def _make_http_response(msg, mimetype = 'text/plain'): return ('HTTP/1.1 200 OK\r\n' + + 'Keep-Alive: timeout=99, max=99\r\n' + + 'Connection: Keep-Alive\r\n' + 'Content-Length: %d\r\n' % len(msg) + 'Content-Type: %s\r\n\r\n' % mimetype + msg) @@ -15,7 +17,21 @@ num_messages = 0 +strands = 0 + def example_http_server_coroutine(addr): + global strands + strands += 1 + my_id = strands + while 1: + try: + yield _process_one_request(addr) + except GeneratorExit: + #print "%d: closing!" % my_id + raise + #print "%d: processed one request!" % my_id + +def _process_one_request(addr): global num_messages request = yield until_received(terminator = '\r\n\r\n') request = request.splitlines()