当前位置: 首页>>代码示例>>Python>>正文


Python LinkedList.currentValue方法代码示例

本文整理汇总了Python中linkedlist.LinkedList.currentValue方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.currentValue方法的具体用法?Python LinkedList.currentValue怎么用?Python LinkedList.currentValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在linkedlist.LinkedList的用法示例。


在下文中一共展示了LinkedList.currentValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Receiver

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import currentValue [as 别名]
class Receiver():

    def __init__(self, packet_sender):
        print 'Init Receiver'

        # TODO: have this be a DuplexStream instead of an EventEmitter.
        # TODO: the Receiver should never send raw packets to the end host. It should
        #      only be acknowledgement packets. Please see [1]

        self.ee = EventEmitter()

        self._synced = False
        self._next_sequence_number = 0

        def sort_by_sequence(packet_a, packet_b):
            return packet_a.get_sequence_number() - packet_b.get_sequence_number()

        self._packets = LinkedList(sort_by_sequence)
        self._packet_sender = packet_sender
        self._closed = False


    def receive(self, packet):
        if self._closed:
            # Since this is closed, don't do anything.
            return

        # Ignores packets that have a sequence number less than the next sequence
        # number
        if not packet.getIsSynchronize() and packet.getSequenceNumber() < self._sync_sequence_number:
            return

        if packet.getIsSynchronize() and not self._synced:
            # This is the beginning of the stream.

            if packet.getSequenceNumber() is self._sync_sequence_number:
              self._packet_sender.send(Packet.createAcknowledgementPacket(packet.getSequenceNumber()))
              return

            # Send the packet upstream, send acknowledgement packet to end host, and
            # increment the next expected packet.
            self._packets.clear()
            self.ee.emit('data', packet.getPayload())
            self._packet_sender.send(Packet.createAcknowledgementPacket(packet.getSequenceNumber()))
            self._packets.insert(packet)
            self._next_sequence_number = packet.getSequenceNumber() + 1
            self._synced = True
            self._sync_sequence_number = packet.getSequenceNumber()


            if packet.getIsReset():
                self.ee.emit('_reset')
                self._synced = False

            # We're done.
            return

        elif (packet.getIsReset()):
            self.ee.emit('_reset')
            self.ee._synced = False

        elif not self._synced:
            # If we are not synchronized with sender, then this means that we should
            # wait for the end host to send a synchronization packet.

            # We are done.
            return

        elif packet.getSequenceNumber() < self._syncSequenceNumber:
            # This is a troll packet. Ignore it.
            return

        elif packet.getSequenceNumber() >= (self._packets.currentValue().getSequenceNumber() + constants.WINDOW_SIZE):
            # This means that the next packet received is not within the window size.
            self.ee.emit('_window_size_exceeded')
            return

        # This means that we should simply insert the packet. If the packet's
        # sequence number is the one that we were expecting, then send it upstream,
        # acknowledge the packet, and increment the next expected sequence number.
        #
        # Once acknowledged, check to see if there aren't any more pending packets
        # after the current packet. If there are, then check to see if the next
        # packet is the expected packet number. If it is, then start the
        # acknowledgement process anew.

        result = self._packets.insert(packet)

        if result is LinkedList.InsertionResult.INSERTED:
            self._pushIfExpectedSequence(packet)
        elif result is LinkedList.InsertionResult.EXISTS:
            self._packet_sender.send(Packet.createAcknowledgementPacket(packet.getSequenceNumber()))

    def _pushIfExpectedSequence(self, packet):
        if packet.get_sequence_number() is self._next_sequence_number:
            self.ee.emit('data', packet.getPayload())
            # [1] Never send packets directly!
            self._packet_sender.send(Packet.createAcknowledgementPacket(packet.getSequenceNumber()))
            self._nextSequenceNumber += 1
            self._packets.seek()
#.........这里部分代码省略.........
开发者ID:hoffmabc,项目名称:python-rudp,代码行数:103,代码来源:receiver.py


注:本文中的linkedlist.LinkedList.currentValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。