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.Connection Class Reference
Inheritance diagram for MoinMoin.support.flup.server.fcgi_base.Connection:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def run
def process_input
def writeRecord
def end_request

Public Attributes

 server

Private Member Functions

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

Private Attributes

 _sock
 _addr
 _requests
 _keepGoing

Static Private Attributes

 _multiplexed = False
 _inputStreamClass = InputStream

Detailed Description

A Connection with the web server.

Each Connection is associated with a single socket (which is
connected to the web server) and is responsible for handling all
the FastCGI message processing for that socket.

Definition at line 607 of file fcgi_base.py.


Constructor & Destructor Documentation

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

Reimplemented in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 618 of file fcgi_base.py.

00618 
00619     def __init__(self, sock, addr, server):
00620         self._sock = sock
00621         self._addr = addr
00622         self.server = server
00623 
00624         # Active Requests for this Connection, mapped by request ID.
00625         self._requests = {}


Member Function Documentation

Close the Connection's socket.

Reimplemented in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 626 of file fcgi_base.py.

00626 
00627     def _cleanupSocket(self):
00628         """Close the Connection's socket."""
00629         try:
00630             self._sock.shutdown(socket.SHUT_WR)
00631         except:
00632             return
00633         try:
00634             while True:
00635                 r, w, e = select.select([self._sock], [], [])
00636                 if not r or not self._sock.recv(1024):
00637                     break
00638         except:
00639             pass
00640         self._sock.close()
        

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 in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 752 of file fcgi_base.py.

00752 
00753     def _do_abort_request(self, inrec):
00754         """
00755         Handle an FCGI_ABORT_REQUEST from the web server.
00756 
00757         We just mark a flag in the associated Request.
00758         """
00759         req = self._requests.get(inrec.requestId)
00760         if req is not None:
00761             req.aborted = True

Here is the caller graph for this function:

Handle an FCGI_BEGIN_REQUEST from the web server.

Reimplemented in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 738 of file fcgi_base.py.

00738 
00739     def _do_begin_request(self, inrec):
00740         """Handle an FCGI_BEGIN_REQUEST from the web server."""
00741         role, flags = struct.unpack(FCGI_BeginRequestBody, inrec.contentData)
00742 
00743         req = self.server.request_class(self, self._inputStreamClass)
00744         req.requestId, req.role, req.flags = inrec.requestId, role, flags
00745         req.aborted = False
00746 
00747         if not self._multiplexed and self._requests:
00748             # Can't multiplex requests.
00749             self.end_request(req, 0L, FCGI_CANT_MPX_CONN, remove=False)
00750         else:
00751             self._requests[inrec.requestId] = req

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.flup.server.fcgi_base.Connection._do_data (   self,
  inrec 
) [private]
Handle the FCGI_DATA stream.

Reimplemented in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 789 of file fcgi_base.py.

00789 
00790     def _do_data(self, inrec):
00791         """Handle the FCGI_DATA stream."""
00792         req = self._requests.get(inrec.requestId)
00793         if req is not None:
00794             req.data.add_data(inrec.contentData)

Here is the caller graph for this function:

Handle an FCGI_GET_VALUES request from the web server.

Definition at line 724 of file fcgi_base.py.

00724 
00725     def _do_get_values(self, inrec):
00726         """Handle an FCGI_GET_VALUES request from the web server."""
00727         outrec = Record(FCGI_GET_VALUES_RESULT)
00728 
00729         pos = 0
00730         while pos < inrec.contentLength:
00731             pos, (name, value) = decode_pair(inrec.contentData, pos)
00732             cap = self.server.capability.get(name)
00733             if cap is not None:
00734                 outrec.contentData += encode_pair(name, str(cap))
00735 
00736         outrec.contentLength = len(outrec.contentData)
00737         self.writeRecord(outrec)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.flup.server.fcgi_base.Connection._do_params (   self,
  inrec 
) [private]
Handle an FCGI_PARAMS Record.

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

Reimplemented in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 767 of file fcgi_base.py.

00767 
00768     def _do_params(self, inrec):
00769         """
00770         Handle an FCGI_PARAMS Record.
00771 
00772         If the last FCGI_PARAMS Record is received, start the request.
00773         """
00774         req = self._requests.get(inrec.requestId)
00775         if req is not None:
00776             if inrec.contentLength:
00777                 pos = 0
00778                 while pos < inrec.contentLength:
00779                     pos, (name, value) = decode_pair(inrec.contentData, pos)
00780                     req.params[name] = value
00781             else:
00782                 self._start_request(req)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.flup.server.fcgi_base.Connection._do_stdin (   self,
  inrec 
) [private]
Handle the FCGI_STDIN stream.

Reimplemented in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 783 of file fcgi_base.py.

00783 
00784     def _do_stdin(self, inrec):
00785         """Handle the FCGI_STDIN stream."""
00786         req = self._requests.get(inrec.requestId)
00787         if req is not None:
00788             req.stdin.add_data(inrec.contentData)

Here is the caller graph for this function:

Handle an unknown request type. Respond accordingly.

Definition at line 795 of file fcgi_base.py.

00795 
00796     def _do_unknown_type(self, inrec):
00797         """Handle an unknown request type. Respond accordingly."""
00798         outrec = Record(FCGI_UNKNOWN_TYPE)
00799         outrec.contentData = struct.pack(FCGI_UnknownTypeBody, inrec.type)
00800         outrec.contentLength = FCGI_UnknownTypeBody_LEN
00801         self.writeRecord(rec)
        

Here is the call graph for this function:

Here is the caller graph for this function:

Run the request.

Reimplemented in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 762 of file fcgi_base.py.

00762 
00763     def _start_request(self, req):
00764         """Run the request."""
00765         # Not multiplexed, so run it inline.
00766         req.run()

Here is the caller graph for this function:

def MoinMoin.support.flup.server.fcgi_base.Connection.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 in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 700 of file fcgi_base.py.

00700 
00701                     protocolStatus=FCGI_REQUEST_COMPLETE, remove=True):
00702         """
00703         End a Request.
00704 
00705         Called by Request objects. An FCGI_END_REQUEST Record is
00706         sent to the web server. If the web server no longer requires
00707         the connection, the socket is closed, thereby ending this
00708         Connection (run() returns).
00709         """
00710         rec = Record(FCGI_END_REQUEST, req.requestId)
00711         rec.contentData = struct.pack(FCGI_EndRequestBody, appStatus,
00712                                       protocolStatus)
00713         rec.contentLength = FCGI_EndRequestBody_LEN
00714         self.writeRecord(rec)
00715 
00716         if remove:
00717             del self._requests[req.requestId]
00718 
00719         if __debug__: _debug(2, 'end_request: flags = %d' % req.flags)
00720 
00721         if not (req.flags & FCGI_KEEP_CONN) and not self._requests:
00722             self._cleanupSocket()
00723             self._keepGoing = False

Here is the call graph for this function:

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 in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 693 of file fcgi_base.py.

00693 
00694     def writeRecord(self, rec):
00695         """
00696         Write a Record to the socket.
00697         """
00698         rec.write(self._sock)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 620 of file fcgi_base.py.

Reimplemented in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 616 of file fcgi_base.py.

Definition at line 643 of file fcgi_base.py.

Reimplemented in MoinMoin.support.flup.server.fcgi_base.MultiplexedConnection.

Definition at line 615 of file fcgi_base.py.

Definition at line 624 of file fcgi_base.py.

Definition at line 619 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: