1e66f31c5Sopenharmony_ci
2e66f31c5Sopenharmony_ci.. _request:
3e66f31c5Sopenharmony_ci
4e66f31c5Sopenharmony_ci:c:type:`uv_req_t` --- Base request
5e66f31c5Sopenharmony_ci===================================
6e66f31c5Sopenharmony_ci
7e66f31c5Sopenharmony_ci`uv_req_t` is the base type for all libuv request types.
8e66f31c5Sopenharmony_ci
9e66f31c5Sopenharmony_ciStructures are aligned so that any libuv request can be cast to `uv_req_t`.
10e66f31c5Sopenharmony_ciAll API functions defined here work with any request type.
11e66f31c5Sopenharmony_ci
12e66f31c5Sopenharmony_ci
13e66f31c5Sopenharmony_ciData types
14e66f31c5Sopenharmony_ci----------
15e66f31c5Sopenharmony_ci
16e66f31c5Sopenharmony_ci.. c:type:: uv_req_t
17e66f31c5Sopenharmony_ci
18e66f31c5Sopenharmony_ci    The base libuv request structure.
19e66f31c5Sopenharmony_ci
20e66f31c5Sopenharmony_ci.. c:type:: uv_any_req
21e66f31c5Sopenharmony_ci
22e66f31c5Sopenharmony_ci    Union of all request types.
23e66f31c5Sopenharmony_ci
24e66f31c5Sopenharmony_ci
25e66f31c5Sopenharmony_ciPublic members
26e66f31c5Sopenharmony_ci^^^^^^^^^^^^^^
27e66f31c5Sopenharmony_ci
28e66f31c5Sopenharmony_ci.. c:member:: void* uv_req_t.data
29e66f31c5Sopenharmony_ci
30e66f31c5Sopenharmony_ci    Space for user-defined arbitrary data. libuv does not use this field.
31e66f31c5Sopenharmony_ci
32e66f31c5Sopenharmony_ci.. c:member:: uv_req_type uv_req_t.type
33e66f31c5Sopenharmony_ci
34e66f31c5Sopenharmony_ci    Indicated the type of request. Readonly.
35e66f31c5Sopenharmony_ci
36e66f31c5Sopenharmony_ci    ::
37e66f31c5Sopenharmony_ci
38e66f31c5Sopenharmony_ci        typedef enum {
39e66f31c5Sopenharmony_ci            UV_UNKNOWN_REQ = 0,
40e66f31c5Sopenharmony_ci            UV_REQ,
41e66f31c5Sopenharmony_ci            UV_CONNECT,
42e66f31c5Sopenharmony_ci            UV_WRITE,
43e66f31c5Sopenharmony_ci            UV_SHUTDOWN,
44e66f31c5Sopenharmony_ci            UV_UDP_SEND,
45e66f31c5Sopenharmony_ci            UV_FS,
46e66f31c5Sopenharmony_ci            UV_WORK,
47e66f31c5Sopenharmony_ci            UV_GETADDRINFO,
48e66f31c5Sopenharmony_ci            UV_GETNAMEINFO,
49e66f31c5Sopenharmony_ci            UV_REQ_TYPE_MAX,
50e66f31c5Sopenharmony_ci        } uv_req_type;
51e66f31c5Sopenharmony_ci
52e66f31c5Sopenharmony_ci
53e66f31c5Sopenharmony_ciAPI
54e66f31c5Sopenharmony_ci---
55e66f31c5Sopenharmony_ci
56e66f31c5Sopenharmony_ci.. c:macro:: UV_REQ_TYPE_MAP(iter_macro)
57e66f31c5Sopenharmony_ci
58e66f31c5Sopenharmony_ci    Macro that expands to a series of invocations of `iter_macro` for
59e66f31c5Sopenharmony_ci    each of the request types. `iter_macro` is invoked with two
60e66f31c5Sopenharmony_ci    arguments: the name of the `uv_req_type` element without the `UV_`
61e66f31c5Sopenharmony_ci    prefix, and the name of the corresponding structure type without the
62e66f31c5Sopenharmony_ci    `uv_` prefix and `_t` suffix.
63e66f31c5Sopenharmony_ci
64e66f31c5Sopenharmony_ci.. c:function:: int uv_cancel(uv_req_t* req)
65e66f31c5Sopenharmony_ci
66e66f31c5Sopenharmony_ci    Cancel a pending request. Fails if the request is executing or has finished
67e66f31c5Sopenharmony_ci    executing.
68e66f31c5Sopenharmony_ci
69e66f31c5Sopenharmony_ci    Returns 0 on success, or an error code < 0 on failure.
70e66f31c5Sopenharmony_ci
71e66f31c5Sopenharmony_ci    Only cancellation of :c:type:`uv_fs_t`, :c:type:`uv_getaddrinfo_t`,
72e66f31c5Sopenharmony_ci    :c:type:`uv_getnameinfo_t`, :c:type:`uv_random_t` and :c:type:`uv_work_t`
73e66f31c5Sopenharmony_ci    requests is currently supported.
74e66f31c5Sopenharmony_ci
75e66f31c5Sopenharmony_ci    Cancelled requests have their callbacks invoked some time in the future.
76e66f31c5Sopenharmony_ci    It's **not** safe to free the memory associated with the request until the
77e66f31c5Sopenharmony_ci    callback is called.
78e66f31c5Sopenharmony_ci
79e66f31c5Sopenharmony_ci    Here is how cancellation is reported to the callback:
80e66f31c5Sopenharmony_ci
81e66f31c5Sopenharmony_ci    * A :c:type:`uv_fs_t` request has its req->result field set to `UV_ECANCELED`.
82e66f31c5Sopenharmony_ci
83e66f31c5Sopenharmony_ci    * A :c:type:`uv_work_t`, :c:type:`uv_getaddrinfo_t`,
84e66f31c5Sopenharmony_ci      :c:type:`uv_getnameinfo_t` or :c:type:`uv_random_t` request has its
85e66f31c5Sopenharmony_ci      callback invoked with status == `UV_ECANCELED`.
86e66f31c5Sopenharmony_ci
87e66f31c5Sopenharmony_ci.. c:function:: size_t uv_req_size(uv_req_type type)
88e66f31c5Sopenharmony_ci
89e66f31c5Sopenharmony_ci    Returns the size of the given request type. Useful for FFI binding writers
90e66f31c5Sopenharmony_ci    who don't want to know the structure layout.
91e66f31c5Sopenharmony_ci
92e66f31c5Sopenharmony_ci.. c:function:: void* uv_req_get_data(const uv_req_t* req)
93e66f31c5Sopenharmony_ci
94e66f31c5Sopenharmony_ci    Returns `req->data`.
95e66f31c5Sopenharmony_ci
96e66f31c5Sopenharmony_ci    .. versionadded:: 1.19.0
97e66f31c5Sopenharmony_ci
98e66f31c5Sopenharmony_ci.. c:function:: void* uv_req_set_data(uv_req_t* req, void* data)
99e66f31c5Sopenharmony_ci
100e66f31c5Sopenharmony_ci    Sets `req->data` to `data`.
101e66f31c5Sopenharmony_ci
102e66f31c5Sopenharmony_ci    .. versionadded:: 1.19.0
103e66f31c5Sopenharmony_ci
104e66f31c5Sopenharmony_ci.. c:function:: uv_req_type uv_req_get_type(const uv_req_t* req)
105e66f31c5Sopenharmony_ci
106e66f31c5Sopenharmony_ci    Returns `req->type`.
107e66f31c5Sopenharmony_ci
108e66f31c5Sopenharmony_ci    .. versionadded:: 1.19.0
109e66f31c5Sopenharmony_ci
110e66f31c5Sopenharmony_ci.. c:function:: const char* uv_req_type_name(uv_req_type type)
111e66f31c5Sopenharmony_ci
112e66f31c5Sopenharmony_ci    Returns the name for the equivalent struct for a given request type,
113e66f31c5Sopenharmony_ci    e.g. `"connect"` (as in :c:type:`uv_connect_t`) for `UV_CONNECT`.
114e66f31c5Sopenharmony_ci
115e66f31c5Sopenharmony_ci    If no such request type exists, this returns `NULL`.
116e66f31c5Sopenharmony_ci
117e66f31c5Sopenharmony_ci    .. versionadded:: 1.19.0
118