Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection Class Reference
Inheritance diagram for MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def writeRecord
def end_request
def run
def process_input

Public Attributes

 server

Private Member Functions

def _cleanupSocket
def _do_begin_request
def _do_abort_request
def _start_request
def _do_params
def _do_stdin
def _do_data

Private Attributes

 _lock

Static Private Attributes

 _multiplexed = True
 _inputStreamClass = MultiplexedInputStream

Detailed Description

A version of Connection capable of handling multiple requests
simultaneously.

Definition at line 802 of file fcgi_base.py.


Constructor & Destructor Documentation

def MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.__init__ (   self,
  sock,
  addr,
  server 
)

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 810 of file fcgi_base.py.

00810 
00811     def __init__(self, sock, addr, server):
00812         super(MultiplexedConnection, self).__init__(sock, addr, server)
00813 
00814         # Used to arbitrate access to self._requests.
00815         lock = threading.RLock()
00816 
00817         # Notification is posted everytime a request completes, allowing us
00818         # to quit cleanly.
00819         self._lock = threading.Condition(lock)


Member Function Documentation

Close the Connection's socket.

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 820 of file fcgi_base.py.

00820 
00821     def _cleanupSocket(self):
00822         # Wait for any outstanding requests before closing the socket.
00823         self._lock.acquire()
00824         while self._requests:
00825             self._lock.wait()
00826         self._lock.release()
00827 
00828         super(MultiplexedConnection, self)._cleanupSocket()
        

Here is the caller graph for this function:

Handle an FCGI_ABORT_REQUEST from the web server.

We just mark a flag in the associated Request.

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 857 of file fcgi_base.py.

00857 
00858     def _do_abort_request(self, inrec):
00859         self._lock.acquire()
00860         try:
00861             super(MultiplexedConnection, self)._do_abort_request(inrec)
00862         finally:
00863             self._lock.release()

Handle an FCGI_BEGIN_REQUEST from the web server.

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 850 of file fcgi_base.py.

00850 
00851     def _do_begin_request(self, inrec):
00852         self._lock.acquire()
00853         try:
00854             super(MultiplexedConnection, self)._do_begin_request(inrec)
00855         finally:
00856             self._lock.release()

Handle the FCGI_DATA stream.

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 881 of file fcgi_base.py.

00881 
00882     def _do_data(self, inrec):
00883         self._lock.acquire()
00884         try:
00885             super(MultiplexedConnection, self)._do_data(inrec)
00886         finally:
00887             self._lock.release()
        
Handle an FCGI_PARAMS Record.

If the last FCGI_PARAMS Record is received, start the request.

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 867 of file fcgi_base.py.

00867 
00868     def _do_params(self, inrec):
00869         self._lock.acquire()
00870         try:
00871             super(MultiplexedConnection, self)._do_params(inrec)
00872         finally:
00873             self._lock.release()

Handle the FCGI_STDIN stream.

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 874 of file fcgi_base.py.

00874 
00875     def _do_stdin(self, inrec):
00876         self._lock.acquire()
00877         try:
00878             super(MultiplexedConnection, self)._do_stdin(inrec)
00879         finally:
00880             self._lock.release()

Run the request.

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 864 of file fcgi_base.py.

00864 
00865     def _start_request(self, req):
00866         thread.start_new_thread(req.run, ())

def MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.end_request (   self,
  req,
  appStatus = 0L,
  protocolStatus = FCGI_REQUEST_COMPLETE,
  remove = True 
)
End a Request.

Called by Request objects. An FCGI_END_REQUEST Record is
sent to the web server. If the web server no longer requires
the connection, the socket is closed, thereby ending this
Connection (run() returns).

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 840 of file fcgi_base.py.

00840 
00841                     protocolStatus=FCGI_REQUEST_COMPLETE, remove=True):
00842         self._lock.acquire()
00843         try:
00844             super(MultiplexedConnection, self).end_request(req, appStatus,
00845                                                            protocolStatus,
00846                                                            remove)
00847             self._lock.notify()
00848         finally:
00849             self._lock.release()

Here is the caller graph for this function:

Attempt to read a single Record from the socket and process it.

Definition at line 656 of file fcgi_base.py.

00656 
00657     def process_input(self):
00658         """Attempt to read a single Record from the socket and process it."""
00659         # Currently, any children Request threads notify this Connection
00660         # that it is no longer needed by closing the Connection's socket.
00661         # We need to put a timeout on select, otherwise we might get
00662         # stuck in it indefinitely... (I don't like this solution.)
00663         while self._keepGoing:
00664             try:
00665                 r, w, e = select.select([self._sock], [], [], 1.0)
00666             except ValueError:
00667                 # Sigh. ValueError gets thrown sometimes when passing select
00668                 # a closed socket.
00669                 raise EOFError
00670             if r: break
00671         if not self._keepGoing:
00672             return
00673         rec = Record()
00674         rec.read(self._sock)
00675 
00676         if rec.type == FCGI_GET_VALUES:
00677             self._do_get_values(rec)
00678         elif rec.type == FCGI_BEGIN_REQUEST:
00679             self._do_begin_request(rec)
00680         elif rec.type == FCGI_ABORT_REQUEST:
00681             self._do_abort_request(rec)
00682         elif rec.type == FCGI_PARAMS:
00683             self._do_params(rec)
00684         elif rec.type == FCGI_STDIN:
00685             self._do_stdin(rec)
00686         elif rec.type == FCGI_DATA:
00687             self._do_data(rec)
00688         elif rec.requestId == FCGI_NULL_REQUEST_ID:
00689             self._do_unknown_type(rec)
00690         else:
00691             # Need to complain about this.
00692             pass

Here is the call graph for this function:

Begin processing data from the socket.

Definition at line 641 of file fcgi_base.py.

00641 
00642     def run(self):
00643         """Begin processing data from the socket."""
00644         self._keepGoing = True
00645         while self._keepGoing:
00646             try:
00647                 self.process_input()
00648             except (EOFError, KeyboardInterrupt):
00649                 break
00650             except (select.error, socket.error), e:
00651                 if e[0] == errno.EBADF: # Socket was closed by Request.
00652                     break
00653                 raise
00654 
00655         self._cleanupSocket()

Write a Record to the socket.

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 829 of file fcgi_base.py.

00829 
00830     def writeRecord(self, rec):
00831         # Must use locking to prevent intermingling of Records from different
00832         # threads.
00833         self._lock.acquire()
00834         try:
00835             # Probably faster than calling super. ;)
00836             rec.write(self._sock)
00837         finally:
00838             self._lock.release()

Here is the call graph for this function:


Member Data Documentation

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 808 of file fcgi_base.py.

Definition at line 818 of file fcgi_base.py.

Reimplemented from MoinMoin.support.flup.server.fcgi_base.Connection.

Definition at line 807 of file fcgi_base.py.

Definition at line 621 of file fcgi_base.py.


The documentation for this class was generated from the following file: