Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1876

Show
Ignore:
Timestamp:
01/21/08 19:02:07
Author:
fumanchu
Message:

Potential fix for #598. Getting SSL errors though.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/598-sendall/cherrypy/wsgiserver/__init__.py

    r1871 r1876  
    203203    A single HTTP connection may consist of multiple request/response pairs. 
    204204     
    205     sendall: the 'sendall' method from the connection's fileobject. 
     205    send: the 'send' method from the connection's socket object. 
    206206    wsgi_app: the WSGI application to call. 
    207207    environ: a partial WSGI environ (server and connection entries). 
     
    236236    max_request_body_size = 0 
    237237     
    238     def __init__(self, sendall, environ, wsgi_app): 
     238    def __init__(self, send, environ, wsgi_app): 
    239239        self.rfile = environ['wsgi.input'] 
    240         self.sendall = sendall 
     240        self.send = send 
    241241        self.environ = environ.copy() 
    242242        self.wsgi_app = wsgi_app 
     
    569569        else: 
    570570            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 
    571581     
    572582    def send_headers(self): 
     
    712722     
    713723    rfile: a fileobject for reading from the socket. 
    714     sendall: a function for writing (+ flush) to the socket. 
     724    send: a function for writing (+ flush) to the socket. 
    715725    """ 
    716726     
     
    737747            self.rfile = SSL_fileobject(sock, "r", self.rbufsize) 
    738748            self.rfile.ssl_timeout = timeout 
    739             self.sendall = _ssl_wrap_method(sock.sendall
     749            self.send = _ssl_wrap_method(sock.send
    740750        else: 
    741751            self.rfile = sock.makefile("rb", self.rbufsize) 
    742             self.sendall = sock.sendall 
     752            self.send = sock.send 
    743753         
    744754        # Wrap wsgi.input but not HTTPConnection.rfile itself. 
     
    756766                # get written to the previous request. 
    757767                req = None 
    758                 req = self.RequestHandlerClass(self.sendall, self.environ, 
     768                req = self.RequestHandlerClass(self.send, self.environ, 
    759769                                               self.wsgi_app) 
    760770                 
     
    778788            raise 
    779789        except NoSSLError: 
    780             # Unwrap our sendall 
    781             req.sendall = self.socket._sock.sendall 
     790            # Unwrap our send 
     791            req.send = self.socket._sock.send 
    782792            req.simple_response("400 Bad Request", 
    783793                                "The client sent a plain HTTP request, but " 
     
    790800        """Close the socket underlying this connection.""" 
    791801        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         
    792810        self.socket.close() 
    793811 

Hosted by WebFaction

Log in as guest/cpguest to create tickets