@@ -13,16 +13,12 @@ import ll = uv_ll;
13
13
14
14
#[ doc = "
15
15
Used to abstract-away direct interaction with a libuv loop.
16
-
17
- # Arguments
18
-
19
- * async_handle - a pointer to a pointer to a uv_async_t struct used to 'poke'
20
- the C uv loop to process any pending callbacks
21
-
22
- * op_chan - a channel used to send function callbacks to be processed
23
- by the C uv loop
24
16
" ]
25
17
enum high_level_loop {
18
+ #[ doc="
19
+ `high_level_loop` variant that carries a `comm::chan` and
20
+ a `*ll::uv_async_t`.
21
+ " ]
26
22
simple_task_loop( {
27
23
async_handle : * ll:: uv_async_t ,
28
24
op_chan : comm:: chan < high_level_msg >
@@ -34,23 +30,36 @@ Represents the range of interactions with a `high_level_loop`
34
30
" ]
35
31
enum high_level_msg {
36
32
interaction ( fn ~( * libc:: c_void ) ) ,
33
+ #[ doc="
34
+ For use in libraries that roll their own `high_level_loop` (like
35
+ `std::uv::global_loop`)
36
+
37
+ Is used to signal to the loop that it should close the internally-held
38
+ async handle and do a sanity check to make sure that all other handles are
39
+ closed, causing a failure otherwise. This should not be sent/used from
40
+ 'normal' user code.
41
+ " ]
37
42
teardown_loop
38
43
}
39
44
40
45
#[ doc = "
41
- Given a vanilla `uv_loop_t*`
46
+ Useful for anyone who wants to roll their own `high_level_loop`.
42
47
43
48
# Arguments
44
49
45
50
* loop_ptr - a pointer to a currently unused libuv loop. Its `data` field
46
51
will be overwritten before the loop begins
47
- must be a pointer to a clean rust `uv_async_t` record
48
- * msg_po - an active port that receives `high_level_msg`s
49
- * before_run - a unique closure that is invoked after `uv_async_init` is
50
- called on the `async_handle` passed into this callback, just before `uv_run`
51
- is called on the provided `loop_ptr`
52
- * before_msg_drain - a unique closure that is invoked every time the loop is
53
- awoken, but before the port pointed to in the `msg_po` argument is drained
52
+ * msg_po - an active port that receives `high_level_msg`s. You can distribute
53
+ a paired channel to users, along with the `async_handle` returned in the
54
+ following callback (combine them to make a `hl::simpler_task_loop` varient
55
+ of `hl::high_level_loop`)
56
+ * before_run - a unique closure that is invoked before `uv_run()` is called
57
+ on the provided `loop_ptr`. An `async_handle` is passed in which will be
58
+ live for the duration of the loop. You can distribute this to users so that
59
+ they can interact with the loop safely.
60
+ * before_msg_process - a unique closure that is invoked at least once when
61
+ the loop is woken up, and once more for every message that is drained from
62
+ the loop's msg port
54
63
* before_tear_down - called just before the loop invokes `uv_close()` on the
55
64
provided `async_handle`. `uv_run` should return shortly after
56
65
" ]
@@ -93,17 +102,25 @@ Provide a callback to be processed by `a_loop`
93
102
The primary way to do operations again a running `high_level_loop` that
94
103
doesn't involve creating a uv handle via `safe_handle`
95
104
105
+ # Warning
106
+
107
+ This function is the only safe way to interact with _any_ `high_level_loop`.
108
+ Using functions in the `uv::ll` module outside of the `cb` passed into
109
+ this function is _very dangerous_.
110
+
96
111
# Arguments
97
112
98
- * a_loop - a `high_level_loop` that you want to do operations against
113
+ * hl_loop - a `uv::hl:: high_level_loop` that you want to do operations against
99
114
* cb - a function callback to be processed on the running loop's
100
- thread. The only parameter is an opaque pointer to the running
101
- uv_loop_t. In the context of this callback, it is safe to use this pointer
102
- to do various uv_* API calls. _DO NOT_ send this pointer out via ports/chans
115
+ thread. The only parameter passed in is an opaque pointer representing the
116
+ running `uv_loop_t*`. In the context of this callback, it is safe to use
117
+ this pointer to do various uv_* API calls contained within the `uv::ll`
118
+ module. It is not safe to send the `loop_ptr` param to this callback out
119
+ via ports/chans.
103
120
" ]
104
- unsafe fn interact ( a_loop : high_level_loop ,
121
+ unsafe fn interact ( hl_loop : high_level_loop ,
105
122
-cb : fn ~( * libc:: c_void ) ) {
106
- send_high_level_msg ( a_loop , interaction ( cb) ) ;
123
+ send_high_level_msg ( hl_loop , interaction ( cb) ) ;
107
124
}
108
125
109
126
// INTERNAL API
0 commit comments