Пример #1
0
 def test_basic_send(self):
   i = IOWorker()
   i.send("foo")
   self.assertTrue(i._ready_to_send)
   self.assertEqual(i.send_buf, "foo")
   i._consume_send_buf(3)
   self.assertFalse(i._ready_to_send)
Пример #2
0
 def send(self, data):
     if threading.current_thread(
     ).name != "MainThread" and threading.current_thread(
     ).name != "BackgroundIOThread":
         raise RuntimeError("Wrong thread: %s" % threading.current_thread())
     """ send data from the client side. fire and forget. """
     return IOWorker.send(self, data)
Пример #3
0
 def test_not_sent_until_permitted(self):
     i = DeferredIOWorker(IOWorker())
     i.set_receive_handler(self.call_later)
     i.block()
     i.send("foo")
     self.assertFalse(i._io_worker._ready_to_send)
     self.assertFalse(i._send_queue.empty())
     i.unblock()
     self.assertTrue(i._send_queue.empty())
     i._io_worker._consume_send_buf(3)
     self.assertFalse(i._io_worker._ready_to_send)
Пример #4
0
    def test_basic_receive(self):
        i = IOWorker()
        self.data = None

        def d(worker):
            self.data = worker.peek_receive_buf()

        i.set_receive_handler(d)
        i._push_receive_data("bar")
        self.assertEqual(self.data, "bar")
        # d does not consume the data
        i._push_receive_data("hepp")
        self.assertEqual(self.data, "barhepp")
Пример #5
0
 def test_basic_send(self):
   i = IOWorker()
   i.send("foo")
   self.assertTrue(i._ready_to_send)
   self.assertEqual(i.send_buf, "foo")
   i._consume_send_buf(3)
   self.assertFalse(i._ready_to_send)
Пример #6
0
    def test_receive_consume(self):
        i = IOWorker()
        self.data = None

        def consume(worker):
            self.data = worker.peek_receive_buf()
            worker.consume_receive_buf(len(self.data))

        i.set_receive_handler(consume)
        i._push_receive_data("bar")
        self.assertEqual(self.data, "bar")
        # data has been consumed
        i._push_receive_data("hepp")
        self.assertEqual(self.data, "hepp")
Пример #7
0
 def test_basic_receive(self):
   i = IOWorker()
   self.data = None
   def d(worker):
     self.data = worker.peek_receive_buf()
   i.set_receive_handler(d)
   i._push_receive_data("bar")
   self.assertEqual(self.data, "bar")
   # d does not consume the data
   i._push_receive_data("hepp")
   self.assertEqual(self.data, "barhepp")
Пример #8
0
 def test_receive_consume(self):
   i = IOWorker()
   self.data = None
   def consume(worker):
     self.data = worker.peek_receive_buf()
     worker.consume_receive_buf(len(self.data))
   i.set_receive_handler(consume)
   i._push_receive_data("bar")
   self.assertEqual(self.data, "bar")
   # data has been consumed
   i._push_receive_data("hepp")
   self.assertEqual(self.data, "hepp")
Пример #9
0
    def test_receive_consume(self):
        i = DeferredIOWorker(IOWorker())
        i.set_receive_handler(self.call_later)
        self.data = None

        def consume(worker):
            self.data = worker.peek_receive_buf()
            worker.consume_receive_buf(len(self.data))

        i.set_receive_handler(consume)
        i.block()
        i._io_worker._push_receive_data("bar")
        self.assertEqual(self.data, None)
        i.unblock()
        self.assertEqual(self.data, "bar")
        # data has been consumed
        i._io_worker._push_receive_data("hepp")
        self.assertEqual(self.data, "hepp")
Пример #10
0
    def test_not_received_until_permitted(self):
        i = DeferredIOWorker(IOWorker())
        i.set_receive_handler(self.call_later)
        i.block()
        self.data = None

        def d(worker):
            self.data = worker.peek_receive_buf()

        i.set_receive_handler(d)
        i._io_worker._push_receive_data("bar")
        self.assertEqual(self.data, None)
        i.unblock()
        self.assertEqual(self.data, "bar")
        # Now if unblocked, should go through immediately
        # Note: d does not consume the data
        i._io_worker._push_receive_data("hepp")
        self.assertEqual(self.data, "barhepp")
Пример #11
0
 def __init__(self, socket, on_close):
     IOWorker.__init__(self)
     self.socket = socket
     # (on_close factory method hides details of the Select loop)
     self.on_close = on_close
Пример #12
0
 def send(self, data):
   """ send data from the client side. fire and forget. """
   return IOWorker.send(self, data)
Пример #13
0
 def __init__(self, socket, on_close):
     IOWorker.__init__(self)
     self.socket = socket
     self.closed = False
     # (on_close factory method hides details of the Select loop)
     self.on_close = on_close
Пример #14
0
 def send(self, data):
     """ send data from the client side. fire and forget. """
     return IOWorker.send(self, data)
Пример #15
0
 def close(self):
     """ Register this socket to be closed. fire and forget """
     # (don't close until Select loop is ready)
     IOWorker.close(self)
     # on_close is a function not a method
     self.on_close(self)
Пример #16
0
    def send(self, data):
        if threading.current_thread().name != "MainThread" and threading.current_thread().name != "BackgroundIOThread":
            raise RuntimeError("Wrong thread: %s" % threading.current_thread())

        """ send data from the client side. fire and forget. """
        return IOWorker.send(self, data)
Пример #17
0
 def close(self):
     """ Register this socket to be closed. fire and forget """
     # (don't close until Select loop is ready)
     IOWorker.close(self)
     # on_close is a function not a method
     self.on_close(self)