Changeset 1876
- Timestamp:
- 01/21/08 19:02:07
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/598-sendall/cherrypy/wsgiserver/__init__.py
r1871 r1876 203 203 A single HTTP connection may consist of multiple request/response pairs. 204 204 205 send all: the 'sendall' method from the connection's fileobject.205 send: the 'send' method from the connection's socket object. 206 206 wsgi_app: the WSGI application to call. 207 207 environ: a partial WSGI environ (server and connection entries). … … 236 236 max_request_body_size = 0 237 237 238 def __init__(self, send all, environ, wsgi_app):238 def __init__(self, send, environ, wsgi_app): 239 239 self.rfile = environ['wsgi.input'] 240 self.send all = sendall240 self.send = send 241 241 self.environ = environ.copy() 242 242 self.wsgi_app = wsgi_app … … 569 569 else: 570 570 self.sendall(chunk) 571 572 def sendall(self, data): 573 """Sendall for non-blocking sockets.""" 574 while data: 575 try: 576 bytes_sent = self.send(data) 577 data = data[bytes_sent:] 578 except socket.error, e: 579 if e.args[0] not in socket_errors_nonblocking: 580 raise 571 581 572 582 def send_headers(self): … … 712 722 713 723 rfile: a fileobject for reading from the socket. 714 send all: a function for writing (+ flush) to the socket.724 send: a function for writing (+ flush) to the socket. 715 725 """ 716 726 … … 737 747 self.rfile = SSL_fileobject(sock, "r", self.rbufsize) 738 748 self.rfile.ssl_timeout = timeout 739 self.send all = _ssl_wrap_method(sock.sendall)749 self.send = _ssl_wrap_method(sock.send) 740 750 else: 741 751 self.rfile = sock.makefile("rb", self.rbufsize) 742 self.send all = sock.sendall752 self.send = sock.send 743 753 744 754 # Wrap wsgi.input but not HTTPConnection.rfile itself. … … 756 766 # get written to the previous request. 757 767 req = None 758 req = self.RequestHandlerClass(self.send all, self.environ,768 req = self.RequestHandlerClass(self.send, self.environ, 759 769 self.wsgi_app) 760 770 … … 778 788 raise 779 789 except NoSSLError: 780 # Unwrap our send all781 req.send all = self.socket._sock.sendall790 # Unwrap our send 791 req.send = self.socket._sock.send 782 792 req.simple_response("400 Bad Request", 783 793 "The client sent a plain HTTP request, but " … … 790 800 """Close the socket underlying this connection.""" 791 801 self.rfile.close() 802 803 # Python's socket module does NOT call close on the kernel socket 804 # when you call socket.close(). We do so manually here because we 805 # want this server to send a FIN TCP segment immediately. Note this 806 # must be called *before* calling socket.close(), because the latter 807 # drops its reference to the kernel socket. 808 self.socket._sock.close() 809 792 810 self.socket.close() 793 811

