Back to index

moin  1.9.0~rc2
Public Member Functions | Private Member Functions | Private Attributes
MoinMoin.support.flup.server.singleserver.SingleServer Class Reference

List of all members.

Public Member Functions

def __init__
def run

Private Member Functions

def _mainloopPeriodic
def _exit
def _isClientAllowed
def _hupHandler
def _intHandler
def _installSignalHandlers
def _restoreSignalHandlers

Private Attributes

 _jobClass
 _jobArgs
 _keepGoing
 _hupReceived
 _oldSIGs

Detailed Description

Definition at line 47 of file singleserver.py.


Constructor & Destructor Documentation

def MoinMoin.support.flup.server.singleserver.SingleServer.__init__ (   self,
  jobClass = None,
  jobArgs = (),
  kw 
)

Definition at line 48 of file singleserver.py.

00048 
00049     def __init__(self, jobClass=None, jobArgs=(), **kw):
00050         self._jobClass = jobClass
00051         self._jobArgs = jobArgs


Member Function Documentation

def MoinMoin.support.flup.server.singleserver.SingleServer._exit (   self,
  reload = False 
) [private]
Protected convenience method for subclasses to force an exit. Not
really thread-safe, which is why it isn't public.

Definition at line 111 of file singleserver.py.

00111 
00112     def _exit(self, reload=False):
00113         """
00114         Protected convenience method for subclasses to force an exit. Not
00115         really thread-safe, which is why it isn't public.
00116         """
00117         if self._keepGoing:
00118             self._keepGoing = False
00119             self._hupReceived = reload

def MoinMoin.support.flup.server.singleserver.SingleServer._hupHandler (   self,
  signum,
  frame 
) [private]

Definition at line 126 of file singleserver.py.

00126 
00127     def _hupHandler(self, signum, frame):
00128         self._hupReceived = True
00129         self._keepGoing = False

Definition at line 133 of file singleserver.py.

00133 
00134     def _installSignalHandlers(self):
00135         supportedSignals = [signal.SIGINT, signal.SIGTERM]
00136         if hasattr(signal, 'SIGHUP'):
00137             supportedSignals.append(signal.SIGHUP)
00138 
00139         self._oldSIGs = [(x,signal.getsignal(x)) for x in supportedSignals]
00140 
00141         for sig in supportedSignals:
00142             if hasattr(signal, 'SIGHUP') and sig == signal.SIGHUP:
00143                 signal.signal(sig, self._hupHandler)
00144             else:
00145                 signal.signal(sig, self._intHandler)

def MoinMoin.support.flup.server.singleserver.SingleServer._intHandler (   self,
  signum,
  frame 
) [private]

Definition at line 130 of file singleserver.py.

00130 
00131     def _intHandler(self, signum, frame):
00132         self._keepGoing = False

Override to provide access control.

Definition at line 120 of file singleserver.py.

00120 
00121     def _isClientAllowed(self, addr):
00122         """Override to provide access control."""
00123         return True

Called with just about each iteration of the main loop. Meant to
be overridden.

Definition at line 104 of file singleserver.py.

00104 
00105     def _mainloopPeriodic(self):
00106         """
00107         Called with just about each iteration of the main loop. Meant to
00108         be overridden.
00109         """
00110         pass

Definition at line 146 of file singleserver.py.

00146 
00147     def _restoreSignalHandlers(self):
00148         for signum,handler in self._oldSIGs:
00149             signal.signal(signum, handler)

def MoinMoin.support.flup.server.singleserver.SingleServer.run (   self,
  sock,
  timeout = 1.0 
)
The main loop. Pass a socket that is ready to accept() client
connections. Return value will be True or False indiciating whether
or not the loop was exited due to SIGHUP.

Definition at line 52 of file singleserver.py.

00052 
00053     def run(self, sock, timeout=1.0):
00054         """
00055         The main loop. Pass a socket that is ready to accept() client
00056         connections. Return value will be True or False indiciating whether
00057         or not the loop was exited due to SIGHUP.
00058         """
00059         # Set up signal handlers.
00060         self._keepGoing = True
00061         self._hupReceived = False
00062 
00063         # Might need to revisit this?
00064         if not sys.platform.startswith('win'):
00065             self._installSignalHandlers()
00066 
00067         # Set close-on-exec
00068         setCloseOnExec(sock)
00069         
00070         # Main loop.
00071         while self._keepGoing:
00072             try:
00073                 r, w, e = select.select([sock], [], [], timeout)
00074             except select.error, e:
00075                 if e[0] == errno.EINTR:
00076                     continue
00077                 raise
00078 
00079             if r:
00080                 try:
00081                     clientSock, addr = sock.accept()
00082                 except socket.error, e:
00083                     if e[0] in (errno.EINTR, errno.EAGAIN):
00084                         continue
00085                     raise
00086 
00087                 setCloseOnExec(clientSock)
00088                 
00089                 if not self._isClientAllowed(addr):
00090                     clientSock.close()
00091                     continue
00092 
00093                 # Hand off to Connection.
00094                 conn = self._jobClass(clientSock, addr, *self._jobArgs)
00095                 conn.run()
00096 
00097             self._mainloopPeriodic()
00098 
00099         # Restore signal handlers.
00100         self._restoreSignalHandlers()
00101 
00102         # Return bool based on whether or not SIGHUP was received.
00103         return self._hupReceived


Member Data Documentation

Definition at line 60 of file singleserver.py.

Definition at line 50 of file singleserver.py.

Definition at line 49 of file singleserver.py.

Definition at line 59 of file singleserver.py.

Definition at line 138 of file singleserver.py.


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