コード例 #1
0
ファイル: udp.py プロジェクト: BigRLab/flower
    def on_recv(self, handler, addr, data, error):
        with self._lock:
            if addr in self.conns:
                conn = self.conns[addr]

                if error:
                    if error == 1:
                        msg = ""
                    else:
                        msg = bomb(IOError, IOError("uv error: %s" % error))
                else:
                    msg = data

                # emit last message
                conn.queue.append(msg)
                if conn.cr.balance < 0:
                    # someone is waiting, return last message
                    conn.cr.send(self.queue.popleft())

            elif len(self.listeners):
                listener = self.listeners.popleft()
                if error:
                    listener.c.send_exception(IOError, "uv error: %s" % error)
                else:
                    conn = UDPConn(addr)
                    conn.queue.append(data)
                    self.conns[addr] = conn
                    listener.c.send(conn, error)
            else:
                # we should probably do something there to drop connections
                self.task.throw(NoMoreListener)


            schedule()
コード例 #2
0
ファイル: sock.py プロジェクト: benoitc/flower
 def _on_read(self, handle, events, error):
     if error and error is not None:
         self.readable = False
         if error == 1:
             self.closing = True
             msg = ""
         else:
             msg = bomb(IOError, IOError("uv error: %s" % error))
     else:
         self.readable = True
         msg = None
     self.cr.send(msg)
コード例 #3
0
ファイル: sock.py プロジェクト: BigRLab/flower
 def _on_read(self, handle, events, error):
     if error and error is not None:
         self.readable = False
         if error == 1:
             self.closing = True
             msg = ""
         else:
             msg = bomb(IOError, IOError("uv error: %s" % error))
     else:
         self.readable = True
         msg = None
     self.cr.send(msg)
コード例 #4
0
ファイル: test_core.py プロジェクト: RonnyPfannschmidt/flower
 def test_bomb(self):
     try:
         1/0
     except:
         import sys
         b = core.bomb(*sys.exc_info())
     assert b.type is ZeroDivisionError
     if six.PY3:
         assert (str(b.value).startswith('division by zero') or
                 str(b.value).startswith('int division'))
     else:
         assert str(b.value).startswith('integer division')
     assert b.traceback is not None
コード例 #5
0
ファイル: sock.py プロジェクト: benoitc/flower
 def _read(self):
     buf = bytearray(DEFAULT_BUFFER_SIZE)
     try:
         recvd = recv_into(self.client, buf)
         msg =  bytes(buf[0:recvd])
     except socket.error:
         ex = sys.exc_info()[1]
         if ex.args[0] == EBADF:
             msg =  ""
         if ex.args[0] != EWOULDBLOCK or self.timeout == 0.0:
             msg = bomb(ex, sys.exc_info()[2])
         exc_clear()
     return msg
コード例 #6
0
ファイル: test_channel.py プロジェクト: BigRLab/flower
 def test_bomb(self):
     try:
         1/0
     except:
         import sys
         b = core.bomb(*sys.exc_info())
     assert b.type is ZeroDivisionError
     if six.PY3:
         assert (str(b.value).startswith('division by zero') or
                 str(b.value).startswith('int division'))
     else:
         assert str(b.value).startswith('integer division')
     assert b.traceback is not None
コード例 #7
0
ファイル: sock.py プロジェクト: BigRLab/flower
 def _read(self):
     buf = bytearray(DEFAULT_BUFFER_SIZE)
     try:
         recvd = recv_into(self.client, buf)
         msg = bytes(buf[0:recvd])
     except socket.error:
         ex = sys.exc_info()[1]
         if ex.args[0] == EBADF:
             msg = ""
         if ex.args[0] != EWOULDBLOCK or self.timeout == 0.0:
             msg = bomb(ex, sys.exc_info()[2])
         exc_clear()
     return msg
コード例 #8
0
ファイル: tcp.py プロジェクト: benoitc/flower
    def _on_read(self, handle, data, error):
        if error:
            if error == 1: # EOF
                msg = ""
            else:
                msg = bomb(IOError, IOError("uv error: %s" % error))
        else:
            msg = data

        # append the message to the queue
        self.queue.append(msg)

        if self.cr.balance < 0:
            # someone is waiting, return last message
            self.cr.send(self.queue.popleft())
コード例 #9
0
    def _on_read(self, handle, data, error):
        if error:
            if error == 1:  # EOF
                msg = ""
            else:
                msg = bomb(IOError, IOError("uv error: %s" % error))
        else:
            msg = data

        # append the message to the queue
        self.queue.append(msg)

        if self.cr.balance < 0:
            # someone is waiting, return last message
            self.cr.send(self.queue.popleft())
コード例 #10
0
ファイル: sock.py プロジェクト: benoitc/flower
    def read(self):
        if self.closing:
            return ""

        while True:
            try:
                retval = self.queue.popleft()
                if self.cr.balance < 0:
                    self.cr.send(retval)

                if isinstance(retval, bomb):
                    retval.raise_()

                return retval
            except IndexError:
                pass

            msg = None
            buf = bytearray(DEFAULT_BUFFER_SIZE)
            try:
                recvd = recv_into(self.client, buf)
                msg =  bytes(buf[0:recvd])
            except socket.error:
                ex = sys.exc_info()[1]
                if ex.args[0] == EBADF:
                    msg = ""
                    self.closing = True
                if ex.args[0] != EWOULDBLOCK or self.timeout == 0.0:
                    msg = bomb(ex, sys.exc_info()[2])
                    self.closing = True
                exc_clear()

            if msg is None:
                res = self._watch_read()
                if res is not None:
                    self.queue.append(res)

            else:
                self.queue.append(msg)
コード例 #11
0
ファイル: sock.py プロジェクト: BigRLab/flower
    def read(self):
        if self.closing:
            return ""

        while True:
            try:
                retval = self.queue.popleft()
                if self.cr.balance < 0:
                    self.cr.send(retval)

                if isinstance(retval, bomb):
                    retval.raise_()

                return retval
            except IndexError:
                pass

            msg = None
            buf = bytearray(DEFAULT_BUFFER_SIZE)
            try:
                recvd = recv_into(self.client, buf)
                msg = bytes(buf[0:recvd])
            except socket.error:
                ex = sys.exc_info()[1]
                if ex.args[0] == EBADF:
                    msg = ""
                    self.closing = True
                if ex.args[0] != EWOULDBLOCK or self.timeout == 0.0:
                    msg = bomb(ex, sys.exc_info()[2])
                    self.closing = True
                exc_clear()

            if msg is None:
                res = self._watch_read()
                if res is not None:
                    self.queue.append(res)

            else:
                self.queue.append(msg)