qmsk/net/transport/service.py
author Tero Marttila <terom@fixme.fi>
Sat, 26 Sep 2009 16:39:20 +0300
changeset 50 da394bb715af
parent 28 020c89baaa33
permissions -rw-r--r--
try and keep lib.event2.event objects alive (via self-ref) while pending
"""
    Abstract Service interface
"""

class ServiceError (Exception) :
    """
        Service-related error.
    """

class Service (object) :
    """
        A Service listens for incoming connections, handing those connections off as separate objects.

        This is an abstract base class that is further impemented by e.g. TCP or SSL.
    """

    def __init__ (self, endpoint) :
        """
            Listen on the given local endpoint.

                endpoint    - the local Endpoint to provide this service on.
        """

        raise NotImplementedError()

    def accept (self, cls=None) :
        """
            Accept and return a new Transport object representing a connected remote Client.

                cls         - optional transport-specific type to use for the new connection.
        """

        raise NotImplementedError()
    
    def close (self) :
        """
            Explicitly shut down this Service, closing any underlying resources and refusing any new connections.

            This will happen implicitly if the Service is destroyed, this is just the explicit interface.

            This invalidates this Service object for future use.

            This may, in theory, raise an error, which would be supressed if this Service were destroyed.
        """
        
        raise NotImplementedError()