qmsk/net/transport/service.py
author Tero Marttila <terom@fixme.fi>
Mon, 05 Oct 2009 17:12:29 +0300
changeset 58 ecd89f9605ac
parent 28 020c89baaa33
permissions -rw-r--r--
use logging for nc.py
"""
    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()