ConnectEntryPoint.py 929 Bytes
"""
Associate a physical transport layer with a protocol.

Author: Georg Hopp <ghopp@spamtitan.com>
"""

from EndPoint import CommunicationEndPoint

from Transport import Transport

class ConnectEntryPoint(CommunicationEndPoint):
    _EVENTS = {'acc_ready': 0x01}

    def __init__(self, transport, protocol):
        super(ConnectEntryPoint, self).__init__(transport, protocol)
        self._accepted = []

        self._transport.bind()

    def accept(self):
        con = self._transport.accept()

        if not con:
            return False

        while con:
            self._accepted.append(con)
            try:
                con = self._transport.accept()
            except Transport.Error as error:
                con = None

        return True

    def pop(self):
        try:
            return self._accepted.pop()
        except IndexError:
            return None

# vim: set ft=python et ts=8 sw=4 sts=4: