@@ -36,6 +36,31 @@ Requests represent (typically) short-lived operations. These operations can be p
3636handle: write requests are used to write data on a handle; or standalone: getaddrinfo requests
3737don't need a handle they run directly on the loop.
3838
39+ Guidelines for dealing with handles and requests:
40+
41+ 1. If `uv_foo_init() ` succeeds in initializing the handle, you must call
42+ :c:func: `uv_close() `. If the handle's init function errors, you don't
43+ need to do anything.
44+
45+ 2. Only handles are closed, not requests. For example, :c:type: `uv_tcp_t `
46+ is a handle, :c:type: `uv_write_t ` is a request.
47+
48+ 3. The handle's memory can only be reclaimed or reused from inside the
49+ :c:type: `uv_close_cb ` or afterwards, not before.
50+
51+ 4. Most handles have init + start/stop functions; some handles don't.
52+ Example: :c:type: `uv_tcp_t ` vs. :c:type: `uv_process_t `; :c:func: `uv_spawn() `
53+ combines handle initialization and process start into one.
54+
55+ 5. Requests are closed automatically when they complete, or when they are
56+ cancelled with :c:func: `uv_cancel() `.
57+
58+ 6. No additional cleanup is needed except for :c:type: `uv_fs_t ` and
59+ :c:type: `uv_getaddrinfo_t ` requests. For :c:type: `uv_fs_t `, call
60+ :c:func: `uv_fs_req_cleanup() ` once you are done with it; for
61+ :c:type: `uv_getaddrinfo_t `, that's :c:func: `uv_freeaddrinfo() `.
62+
63+ 7. The request's memory can only be reclaimed or reused from that point onward.
3964
4065The I/O loop
4166^^^^^^^^^^^^
0 commit comments