Пример #1
0
    def __init__(self, loop):
        super(TCP, self).__init__(loop)

        handle = uv_tcp_new()
        uv_tcp_init(loop.handle, handle)

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)

        self.handle = handle
Пример #2
0
    def __init__(self, loop, flags=0):
        super(UDP, self).__init__(loop)

        handle = uv_udp_new()
        uv_udp_init(loop.handle, handle, flags)

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)

        self.handle = handle
Пример #3
0
    def __init__(self, loop, fd, readable=False):
        super(TTY, self).__init__(loop)

        handle = uv_tty_new()
        uv_tty_init(loop.handle, handle, fd, int(readable))

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)

        self.handle = handle
Пример #4
0
    def __init__(self, loop=None):
        super(TCP, self).__init__(loop)

        handle = uv_tcp_new()
        uv_tcp_init(self.loop.handle, handle)

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)
        self.tcp_connect_callback = None
        self.handle = handle
Пример #5
0
    def __init__(self, loop=None):
        super(Timer, self).__init__(loop)

        handle = uv_timer_new()
        uv_timer_init(self.loop.handle, handle)

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)

        self.handle = handle
        self.timer_callback = None
Пример #6
0
    def __init__(self, loop=None):
        super(Check, self).__init__(loop)

        handle = uv_check_new()
        uv_check_init(self.loop.handle, handle)

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)

        self.handle = handle
        self.check_callback = None
Пример #7
0
	def __init__(self, loop):
		super(Signal, self).__init__(loop)

		handle = uv_signal_new()
		uv_signal_init(loop.handle, handle)

		self._userdata = ffi.new_handle(self)
		uv_set_pyobj(handle, self._userdata)

		self.handle          = handle
		self.signal_callback = None
Пример #8
0
    def __init__(self, loop, callback=None):
        super(Async, self).__init__(loop)

        handle = uv_async_new()
        uv_async_init(loop.handle, handle, lib.fatuv_async_callback)

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)

        self.handle = handle
        self.async_callback = callback
Пример #9
0
	def __init__(self, loop, fd, callback=None):
		super(Poll, self).__init__(loop)

		handle = uv_poll_new()
		uv_poll_init(loop.handle, handle, fd)

		self.fd = fd

		self._userdata = ffi.new_handle(self)
		uv_set_pyobj(handle, self._userdata)

		self.handle = handle
		self.poll_callback = callback
Пример #10
0
    def __init__(self, loop, path=None, interval=5000, callback=None):
        super(FSPoll, self).__init__(loop)

        handle = uv_fs_poll_new()
        uv_fs_poll_init(loop.handle, handle)

        self.path = path
        self.interval = interval

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)

        self.handle = handle
        self.fs_poll_callback = callback
Пример #11
0
    def __init__(self, loop, path=None, flags=0, callback=None):
        super(FSEvent, self).__init__(loop)

        handle = uv_fs_event_new()
        uv_fs_event_init(loop.handle, handle)

        self.path = path
        self.flags = flags

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)

        self.handle = handle
        self.fs_event_callback = callback
Пример #12
0
    def __init__(self, node, service, callback, loop=None):
        self.loop = loop or Loop.default_loop()
        request = uv_getaddrinfo_ctx_new()
        self.request = request
        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(request, self._userdata)
        self.get_addrinfo_callback = callback

        c_hints = ffi.new('struct fatuv_addrinfo_s*')
        c_hints.ai_family = socket.AF_INET
        c_hints.ai_socktype = socket.SOCK_STREAM
        c_hints.ai_protocol = socket.IPPROTO_TCP
        c_hints.ai_flags = 0

        uv_getaddrinfo(self.loop.handle, request,
                       lib.fatuv_getaddrinfo_callback, node, service, c_hints)
        self.set_pending()
Пример #13
0
	def handles(self):
		handles = set()
		if not self.closed:
			uv_walk(self.handle, lib.fatuv_walk_callback, ffi.new_handle(handles))
		return handles
Пример #14
0
    def __init__(self,
                 loop,
                 arguments,
                 uid=None,
                 gid=None,
                 cwd=None,
                 env=None,
                 stdin=None,
                 stdout=None,
                 stderr=None,
                 stdio=None,
                 flags=lib.FATUV_PROCESS_WINDOWS_HIDE,
                 callback=None):
        super(Process, self).__init__(loop)
        uv_options = ffi.new('fatuv_process_options_t*')
        c_file = ffi.new('char[]', arguments[0].encode())
        uv_options.file = c_file

        c_args_list = [
            ffi.new('char[]', argument.encode()) for argument in arguments
        ]
        c_args_list.append(ffi.NULL)
        c_args = ffi.new('char*[]', c_args_list)
        uv_options.args = c_args

        stdio_count = 3
        if stdio is not None:
            stdio_count += len(stdio)
        uv_options.stdio_count = stdio_count

        c_stdio_containers = ffi.new('fatuv_stdio_container_t[]', stdio_count)
        self.stdin = populate_stdio_container(loop, c_stdio_containers[0],
                                              stdin)
        self.stdout = populate_stdio_container(loop, c_stdio_containers[1],
                                               stdout)
        self.stderr = populate_stdio_container(loop, c_stdio_containers[2],
                                               stderr)
        self.stdio = []
        if stdio is not None:
            for number in range(len(stdio)):
                c_stdio = c_stdio_containers[3 + number]
                fileobj = populate_stdio_container(loop, c_stdio,
                                                   stdio[number])
                self.stdio.append(fileobj)
        uv_options.stdio = c_stdio_containers

        if cwd is not None:
            c_cwd = ffi.new('char[]', cwd.encode())
            uv_options.cwd = c_cwd

        if env is not None:
            c_env_list = [
                ffi.new('char[]', ('%s=%s' % item).encode())
                for item in env.items()
            ]
            c_env_list.append(ffi.NULL)
            c_env = ffi.new('char*[]', c_env_list)
            uv_options.env = c_env

        if uid is not None:
            flags |= lib.UV_PROCESS_SETUID
        if gid is not None:
            flags |= lib.UV_PROCESS_SETGID

        uv_options.uid = uid or 0
        uv_options.gid = gid or 0

        uv_options.flags = flags
        uv_options.exit_cb = lib.fatuv_exit_callback

        self.exit_callback = callback

        handle = uv_process_new()
        code = uv_spawn(loop.handle, handle, uv_options)
        if code != error.STATUS_SUCCESS:
            raise error.UVError(code)

        self._userdata = ffi.new_handle(self)
        uv_set_pyobj(handle, self._userdata)
        self.handle = handle