1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/*
This is intended to be a low-level binding to libuv that very closely mimics
the C libuv API. Does very little right now pending scheduler improvements.
*/
#[cfg(target_os = "linux")];
#[cfg(target_os = "macos")];
export sanity_check;
export loop_t, idle_t;
export loop_new, loop_delete, default_loop, run, unref;
export idle_init, idle_start;
export idle_new;
#[link_name = "rustrt"]
native mod uv {
fn rust_uv_loop_new() -> *loop_t;
fn rust_uv_loop_delete(loop: *loop_t);
fn rust_uv_default_loop() -> *loop_t;
fn rust_uv_run(loop: *loop_t) -> ctypes::c_int;
fn rust_uv_unref(loop: *loop_t);
fn rust_uv_idle_init(loop: *loop_t, idle: *idle_t) -> ctypes::c_int;
fn rust_uv_idle_start(idle: *idle_t, cb: idle_cb) -> ctypes::c_int;
}
#[link_name = "rustrt"]
native mod helpers {
fn rust_uv_size_of_idle_t() -> ctypes::size_t;
}
type opaque_cb = *ctypes::void;
type handle_type = ctypes::enum;
type close_cb = opaque_cb;
type idle_cb = opaque_cb;
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
type handle_private_fields = {
a00: ctypes::c_int,
a01: ctypes::c_int,
a02: ctypes::c_int,
a03: ctypes::c_int,
a04: ctypes::c_int,
a05: ctypes::c_int,
a06: int,
a07: int,
a08: int,
a09: int,
a10: int,
a11: int,
a12: int
};
type handle_fields = {
loop: *loop_t,
type_: handle_type,
close_cb: close_cb,
data: *ctypes::void,
private: handle_private_fields
};
type handle_t = {
fields: handle_fields
};
type loop_t = int;
type idle_t = {
fields: handle_fields
/* private: idle_private_fields */
};
fn idle_init(loop: *loop_t, idle: *idle_t) -> ctypes::c_int {
uv::rust_uv_idle_init(loop, idle)
}
fn idle_start(idle: *idle_t, cb: idle_cb) -> ctypes::c_int {
uv::rust_uv_idle_start(idle, cb)
}
fn default_loop() -> *loop_t {
uv::rust_uv_default_loop()
}
fn loop_new() -> *loop_t {
uv::rust_uv_loop_new()
}
fn loop_delete(loop: *loop_t) {
uv::rust_uv_loop_delete(loop)
}
fn run(loop: *loop_t) -> ctypes::c_int {
uv::rust_uv_run(loop)
}
fn unref(loop: *loop_t) {
uv::rust_uv_unref(loop)
}
fn sanity_check() {
fn check_size(t: str, uv: ctypes::size_t, rust: ctypes::size_t) {
log #fmt("size of %s: uv: %u, rust: %u", t, uv, rust);
assert uv == rust;
}
check_size("idle_t",
helpers::rust_uv_size_of_idle_t(),
sys::size_of::<idle_t>());
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
fn handle_fields_new() -> handle_fields {
{
loop: ptr::null(),
type_: 0u32,
close_cb: ptr::null(),
data: ptr::null(),
private: {
a00: 0i32,
a01: 0i32,
a02: 0i32,
a03: 0i32,
a04: 0i32,
a05: 0i32,
a06: 0,
a07: 0,
a08: 0,
a09: 0,
a10: 0,
a11: 0,
a12: 0
}
}
}
fn idle_new() -> idle_t {
{
fields: handle_fields_new()
}
}
|