示例#1
0
def UDP_recv(self):
    self.check_closed()
    ec = core.get_ec()
    if len(self.read_queue) == 0:
        uv_callback.push(ec.uv__udp_recv, self)
        status = uv.udp_recv_start(self.udp, _udp_alloc_callback_,
                                   _udp_read_callback_once_)
        if status < 0:
            uv_callback.drop(ec.uv__udp_recv, self.udp)
            raise uv_callback.to_error(status)
    if len(self.read_queue) == 0:
        if self.read_greenlet is not None:
            raise unwind(LError(u"async collision"))
        self.read_greenlet = ec.current
        core.switch([ec.eventloop])
    array, nread, status, addr, flags = self.read_queue.pop(0)
    if nread < 0:
        raise uv_callback.to_error(nread)
    if status < 0:
        raise uv_callback.to_error(status)
    if array is None:
        array = Uint8Slice(lltype.nullptr(rffi.UCHARP.TO), 0, None)
    elif array.length != nread:
        array = array.subslice(nread)
    res = Exnihilo()
    res.setattr(u"data", array)
    res.setattr(u"addr", addr)
    res.setattr(u"flags", Integer(rffi.r_long(flags)))
    return res
示例#2
0
def Stream_read(self):
    self.check_closed()
    ec = core.get_ec()
    if len(self.read_queue) == 0:
        uv_callback.push(ec.uv__read, self)
        status = uv.read_start(self.stream, _alloc_callback_,
                               _read_callback_once_)
        if status < 0:
            uv_callback.drop(ec.uv__read, self.stream)
            raise uv_callback.to_error(status)
    if len(self.read_queue) == 0:
        if self.read_greenlet is not None:
            raise unwind(LError(u"async collision"))
        self.read_greenlet = ec.current
        core.switch([ec.eventloop])
    array, nread, status = self.read_queue.pop(0)
    if nread < 0:
        raise uv_callback.to_error(nread)
    if status < 0:
        raise uv_callback.to_error(status)
    if array is None:
        return Uint8Slice(lltype.nullptr(rffi.UCHARP.TO), 0, None)
    if array.length == nread:
        return array
    return array.subslice(nread)
示例#3
0
def Stream_listen(self, backlog):
    self.check_closed()
    ec = core.get_ec()
    uv_callback.push(ec.uv__connection, self)
    status = uv.listen(self.stream, backlog.value, _listen_callback_)
    if status < 0:
        uv_callback.drop(ec.uv__connection, self.stream)
        raise uv_callback.to_error(status)
    else:
        self.listening = True
        return null
示例#4
0
def Watch_init(path):
    ec = core.get_ec()
    path = pathobj.os_stringify(path).encode('utf-8')

    handle = lltype.malloc(uv.fs_event_ptr.TO, flavor='raw', zero=True)
    res = uv.fs_event_init(ec.uv_loop, handle)
    if res < 0:
        lltype.free(handle, flavor='raw')
        raise uv_callback.to_error(res)
    self = Watch(handle)
    uv_callback.push(ec.uv__fs_event, self)

    res = uv.fs_event_start(self.fs_event, _fs_event_cb_, path, 0)
    if res < 0:
        uv_callback.drop(ec.uv__fs_event, self.fs_event)
        Handle_close(self)
        raise uv_callback.to_error(res)
    return self