Exemplo n.º 1
0
    def recv(self, nbits=0):
        '''
        Retrieve `nbits` bits from the hardware.

        If `nbits` > 0, return the bits retrieved. If there are
        no enough bits currently available, `recv` will block until
        enough bits become available.
        If `nbits` is 0, return a iterable which when iterated over
        will retrieve 1 bit at a time. Equivalent to:

            recv()
                while True:
                    yield recv(1)
        '''
        if not nbits:
            return iter(functools.partial(self.recv, 1), None)
        while True:
            while True:
                try:
                    self.ebuffer += self.iqueue.get(block=False)
                except Queue.Empty:
                    break
            if len(self.ebuffer) >= nbits:
                ret, self.ebuffer = utils.split_at(self.ebuffer, nbits)
                return ret
            else:
                mint.wait(0)
                continue
Exemplo n.º 2
0
 def send(self, frame):
     if len(frame) > self._max_frame_size:
         raise NIC.FrameTooLarge()
     while not self.fit(frame, self.obuffer_used):
         mint.wait(0)
     self._oframes.append(frame)
     self.obuffer_used += len(frame)
Exemplo n.º 3
0
 def send(self, frame):
     if len(frame) > self._max_frame_size:
         raise NIC.FrameTooLarge()
     while not self.fit(frame, self.obuffer_used):
         mint.wait(0)
     self._oframes.append(frame)
     self.obuffer_used += len(frame)
Exemplo n.º 4
0
 def run(self):
     out0, out1 = self.setup()
     while True:
         self.ports[1].send(out0.popleft())
         self.ports[0].send(out1.popleft())
         out0.append(self.ports[0].recv())
         out1.append(self.ports[1].recv())
         mint.wait(0)
Exemplo n.º 5
0
 def send(self, frame):
     while True:
         try:
             self.oframes.put(frame, block=False)
             break
         except Queue.Full:
             mint.wait(0)
             continue
Exemplo n.º 6
0
 def recv(self):
     while True:
         try:
             frame = self.iframes.popleft()
             self.ibuffer_used -= len(frame)
             return frame
         except IndexError:
             mint.wait(0)
Exemplo n.º 7
0
 def send(self, frame):
     while True:
         try:
             self.oframes.put(frame, block=False)
             break
         except Queue.Full:
             mint.wait(0)
             continue
Exemplo n.º 8
0
 def recv(self):
     while True:
         try:
             frame = self.iframes.popleft()
             self.ibuffer_used -= len(frame)
             return frame
         except IndexError:
             mint.wait(0)
Exemplo n.º 9
0
 def run(self):
     out0, out1 = self.setup()
     while True:
         self.ports[1].send(out0.popleft())
         self.ports[0].send(out1.popleft())
         out0.append(self.ports[0].recv())
         out1.append(self.ports[1].recv())
         mint.wait(0)
Exemplo n.º 10
0
 def recv(self, n_bits):
     bits = deque()
     while len(bits) < n_bits:
         try:
             bit = self.nic.ibuffer.get(block=False)
             bits.append(bit)
         except Queue.Empty:
             mint.wait(0)
     return ''.join(map(str, bits))
Exemplo n.º 11
0
 def send(self, frame, block=True):
     if len(frame) > self._max_frame_size:
         raise NIC.FrameTooLarge()
     if not block and not self.fit(frame, self.obuffer_used):
         raise mint.exceptions.WouldBlock
     while not self.fit(frame, self.obuffer_used):
         mint.wait(0)
     self._oframes.append(frame)
     self.obuffer_used += len(frame)
Exemplo n.º 12
0
 def link_layer_sender(self):
     while True:
         if self.acked:
             data = self.pull()
             frame = self.NOT_ACK + data
             self.nic.send(frame)
             self.acked = False
         else:
             mint.wait(0)
Exemplo n.º 13
0
 def send(self, frame, block=True):
     if len(frame) > self._max_frame_size:
         raise NIC.FrameTooLarge()
     if not block and not self.fit(frame, self.obuffer_used):
         raise mint.exceptions.WouldBlock
     while not self.fit(frame, self.obuffer_used):
         mint.wait(0)
     self._oframes.append(frame)
     self.obuffer_used += len(frame)
Exemplo n.º 14
0
 def recv(self, n_bits):
     bits = deque()
     while len(bits) < n_bits:
         try:
             bit = self.nic.ibuffer.get(block=False)
             bits.append(bit)
         except Queue.Empty:
             mint.wait(0)
     return ''.join(map(str, bits))
Exemplo n.º 15
0
 def run(self):
     while True:
         self.pull_frame()
         try:
             obit = self.oframe.popleft()
         except IndexError:
             obit = 0
         ibit = self.port.io(obit)
         self.push_frame(ibit)
         mint.wait(0)
Exemplo n.º 16
0
 def run(self):
     while True:
         self.pull_frame()
         try:
             obit = self.oframe.popleft()
         except IndexError:
             obit = 0
         ibit = self.port.io(obit)
         self.push_frame(ibit)
         mint.wait(0)
Exemplo n.º 17
0
 def recv(self, block=True):
     while True:
         try:
             frame = self.iframes.popleft()
             self.ibuffer_used -= len(frame)
             return frame
         except IndexError:
             if block:
                 mint.wait(0)
             else:
                 raise mint.exceptions.WouldBlock
Exemplo n.º 18
0
 def recv(self, block=True):
     while True:
         try:
             frame = self.iframes.popleft()
             self.ibuffer_used -= len(frame)
             return frame
         except IndexError:
             if block:
                 mint.wait(0)
             else:
                 raise mint.exceptions.WouldBlock
Exemplo n.º 19
0
 def run(self):
     while True:
         if not self.oframe:
             self.pull_frame()
         try:
             obit = self.oframe.popleft()
         except IndexError:
             obit = 0
         self.port.send(obit)
         mint.wait(0)
         ibit = self.port.recv()
         self.push_frame(ibit)
         mint.wait(0)
Exemplo n.º 20
0
 def recv(self, nbits):
     while True:
         while True:
             try:
                 self.ebuffer += self.iqueue.get(block=False)
             except Queue.Empty:
                 break
         if len(self.ebuffer) >= nbits:
             ret, self.ebuffer = utils.split_at(self.ebuffer, nbits)
             return ret
         else:
             mint.wait(0)
             continue
Exemplo n.º 21
0
 def sender(self):
     while True:
         if self.acked:
             payload = self.master.pull()
             header = self.build(
                     acking=False,
                     ack=0, # meaningless
                     seq=self.sending_seq)
             self.frame = self.compose(header, payload)
             self.servant.send(self.frame)
             self.timer.start()
             self.acked = False
         else:
             mint.wait(0)
Exemplo n.º 22
0
 def sender(self):
     while True:
         if self.acked:
             payload = self.master.pull()
             header = self.build(
                 acking=False,
                 ack=0,  # meaningless
                 seq=self.sending_seq)
             self.frame = self.compose(header, payload)
             self.servant.send(self.frame)
             self.timer.start()
             self.acked = False
         else:
             mint.wait(0)
Exemplo n.º 23
0
 def sender(self):
     while True:
         while self.events:
             e = self.events.popleft()
             if e.type == RESEND:
                 self.servant.send(frame)
                 e.timer.start()
         if self.allowed_to_send():
             payload = self.master.pull()
             header = self.build(seq=self.oseq)
             frame = self.compose(header, payload)
             self.servant.send(frame)
             timer = self.timer(self.resend_timeout,
                     utils.Bunch(type=RESEND, frame=frame, acked=False))
             self.oframes.append(utils.Bunch(seq=self.oseq, timer=timer))
             self.oseq = (self.oseq + 1) & self.MAX_SEQ
         else:
             mint.wait(0)
Exemplo n.º 24
0
def pop_from(buf):
    while True:
        try:
            return buf.popleft()
        except IndexError:
            mint.wait()
Exemplo n.º 25
0
 def io(self, osymbol=None):
     if osymbol is not None:
         self.osymbol = osymbol
     mint.wait(0)
     return self.isymbol
Exemplo n.º 26
0
 def recver(self):
     while True:
         self.switch_frames()
         mint.wait(0)
Exemplo n.º 27
0
 def recv(self):
     while True:
         try:
             return self.iframes.get(block=False)
         except Queue.Empty:
             mint.wait(1)
Exemplo n.º 28
0
 def pull(self):
     while True:
         try:
             return self.obuffer.popleft()
         except IndexError:
             mint.wait(0)
Exemplo n.º 29
0
 def recv(self):
     while True:
         try:
             return self.iframes.get(block=False)
         except Queue.Empty:
             mint.wait(1)
Exemplo n.º 30
0
def pop_from(buf):
    while True:
        try:
            return buf.popleft()
        except IndexError:
            mint.wait()
Exemplo n.º 31
0
 def recver(self):
     while True:
         self.switch_frames()
         mint.wait(0)
Exemplo n.º 32
0
 def io(self, osymbol=None):
     if osymbol is not None:
         self.osymbol = osymbol
     mint.wait(0)
     return self.isymbol