Example #1
0
 def _callback_(handle, *data):
     ec = core.get_ec()
     resp = pop_handle(getattr(ec, uv_name), handle)
     if len(data) > 0:
         resp.data = data
     resp.pending = False
     if resp.greenlet is not None:
         core.root_switch(ec, [resp.greenlet])
Example #2
0
def _listen_callback_(handle, status):
    status = int(status)
    ec = core.get_ec()
    if status < 0:
        self = uv_callback.drop(ec.uv__connection, handle)
        self.listen_status = status
    else:
        self = uv_callback.peek(ec.uv__connection, handle)
        self.listen_count += 1
    if self.accept_greenlet is not None:
        greenlet, self.accept_greenlet = self.accept_greenlet, None
        core.root_switch(ec, [greenlet])
Example #3
0
def _read_callback_once_(stream, nread, buf):
    ec = core.get_ec()
    self = uv_callback.drop(ec.uv__read, stream)
    for array in self.alloc_buffers:
        if rffi.cast(rffi.CCHARP, array.uint8data) == buf.c_base:
            break
    else:
        array = None
    status = uv.read_stop(stream)
    self.read_queue.append((array, nread, status))
    if self.read_greenlet is not None:
        greenlet, self.read_greenlet = self.read_greenlet, None
        core.root_switch(ec, [greenlet])
Example #4
0
def _udp_read_callback_once_(stream, nread, buf, addr, flags):
    ec = core.get_ec()
    self = uv_callback.drop(ec.uv__udp_recv, stream)
    for array in self.alloc_buffers:
        if rffi.cast(rffi.CCHARP, array.uint8data) == buf.c_base:
            break
    else:
        array = None
    status = uv.udp_recv_stop(stream)
    if addr:
        addr = copy_to_uint8array(rffi.cast(rffi.VOIDP, addr),
                                  rffi.sizeof(uv.sockaddr_storage),
                                  rffi.sizeof(uv.sockaddr_storage))
    else:
        addr = null
    self.read_queue.append((array, nread, status, addr, flags))
    if self.read_greenlet is not None:
        greenlet, self.read_greenlet = self.read_greenlet, None
        core.root_switch(ec, [greenlet])