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