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:function:: 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` and :c:type:`uv_work_t` requests is 73 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` or c:type:`uv_getnameinfo_t` 84 request has its callback invoked with status == `UV_ECANCELED`. 85 86.. c:function:: size_t uv_req_size(uv_req_type type) 87 88 Returns the size of the given request type. Useful for FFI binding writers 89 who don't want to know the structure layout. 90 91.. c:function:: void* uv_req_get_data(const uv_req_t* req) 92 93 Returns `req->data`. 94 95 .. versionadded:: 1.19.0 96 97.. c:function:: void* uv_req_set_data(uv_req_t* req, void* data) 98 99 Sets `req->data` to `data`. 100 101 .. versionadded:: 1.19.0 102 103.. c:function:: uv_req_type uv_req_get_type(const uv_req_t* req) 104 105 Returns `req->type`. 106 107 .. versionadded:: 1.19.0 108 109.. c:function:: const char* uv_req_type_name(uv_req_type type) 110 111 Returns the name for the equivalent struct for a given request type, 112 e.g. `"connect"` (as in :c:type:`uv_connect_t`) for `UV_CONNECT`. 113 114 If no such request type exists, this returns `NULL`. 115 116 .. versionadded:: 1.19.0 117