Skip to content

Commit af60cf4

Browse files
committed
rt: Switch the AIO stuff to the C stack
1 parent 6335529 commit af60cf4

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/lib/aio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import comm;
55
import comm::{chan, port, send, recv};
66
import net;
77

8-
native "rust" mod rustrt {
8+
native "c-stack-cdecl" mod rustrt {
99
type socket;
1010
type server;
1111
fn aio_init();

src/rt/rust_uv.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct socket_data : public task_owned<socket_data> {
5050
struct req_connect : public uv_connect_t, public task_owned<req_connect> {};
5151
struct req_write : public uv_write_t, public task_owned<req_write> {};
5252

53-
extern "C" CDECL void aio_close_socket(void *, socket_data *);
53+
extern "C" CDECL void aio_close_socket(socket_data *);
5454

5555
static uv_idle_s idle_handler;
5656

@@ -59,15 +59,15 @@ static void idle_callback(uv_idle_t* handle, int status) {
5959
task->yield();
6060
}
6161

62-
extern "C" CDECL void aio_init(void *) {
62+
extern "C" CDECL void aio_init() {
6363
rust_task *task = rust_scheduler::get_task();
6464
LOG_UPCALL_ENTRY(task);
6565
iotask = task;
6666
uv_idle_init(uv_default_loop(), &idle_handler);
6767
uv_idle_start(&idle_handler, idle_callback);
6868
}
6969

70-
extern "C" CDECL void aio_run(void *) {
70+
extern "C" CDECL void aio_run() {
7171
rust_task *task = rust_scheduler::get_task();
7272
LOG_UPCALL_ENTRY(task);
7373
idle_handler.data = task;
@@ -76,14 +76,13 @@ extern "C" CDECL void aio_run(void *) {
7676

7777
void nop_close(uv_handle_t* handle) {}
7878

79-
extern "C" CDECL void aio_stop(void *) {
79+
extern "C" CDECL void aio_stop() {
8080
rust_task *task = rust_scheduler::get_task();
8181
LOG_UPCALL_ENTRY(task);
8282
uv_close((uv_handle_t*)&idle_handler, nop_close);
8383
}
8484

85-
static socket_data *make_socket(void *, rust_chan *chan) {
86-
rust_task *task = rust_scheduler::get_task();
85+
static socket_data *make_socket(rust_task *task, rust_chan *chan) {
8786
socket_data *data = new (task, "make_socket") socket_data;
8887
if (!data ||
8988
uv_tcp_init(uv_default_loop(), &data->socket)) {
@@ -153,14 +152,14 @@ static void new_connection(uv_stream_t *socket, int status) {
153152
return;
154153
}
155154
if (uv_accept(socket, (uv_stream_t*)&client->socket)) {
156-
aio_close_socket(client->task, client);
155+
aio_close_socket(client);
157156
server->task->fail();
158157
return;
159158
}
160159
server->chan->send(&client);
161160
}
162161

163-
extern "C" CDECL socket_data *aio_serve(void *, const char *ip, int port,
162+
extern "C" CDECL socket_data *aio_serve(const char *ip, int port,
164163
chan_handle *_chan) {
165164
rust_task *task = rust_scheduler::get_task();
166165
LOG_UPCALL_ENTRY(task);
@@ -172,7 +171,7 @@ extern "C" CDECL socket_data *aio_serve(void *, const char *ip, int port,
172171
goto oom;
173172
if (uv_tcp_bind(&server->socket, addr) ||
174173
uv_listen((uv_stream_t*)&server->socket, 128, new_connection)) {
175-
aio_close_socket(task, server);
174+
aio_close_socket(server);
176175
chan->deref();
177176
return NULL;
178177
}
@@ -207,13 +206,13 @@ static void free_socket(uv_handle_t *handle) {
207206
delete data;
208207
}
209208

210-
extern "C" CDECL void aio_close_socket(void *, socket_data *client) {
209+
extern "C" CDECL void aio_close_socket(socket_data *client) {
211210
rust_task *task = rust_scheduler::get_task();
212211
LOG_UPCALL_ENTRY(task);
213212
uv_close((uv_handle_t*)&client->socket, free_socket);
214213
}
215214

216-
extern "C" CDECL void aio_close_server(void *, socket_data *server,
215+
extern "C" CDECL void aio_close_server(socket_data *server,
217216
chan_handle *_chan) {
218217
rust_task *task = rust_scheduler::get_task();
219218
LOG_UPCALL_ENTRY(task);
@@ -225,11 +224,11 @@ extern "C" CDECL void aio_close_server(void *, socket_data *server,
225224
server->chan->send(&null_client);
226225
server->chan->deref();
227226
server->chan = chan->clone(iotask);
228-
aio_close_socket(task, server);
227+
aio_close_socket(server);
229228
chan->deref();
230229
}
231230

232-
extern "C" CDECL bool aio_is_null_client(void *, socket_data *server) {
231+
extern "C" CDECL bool aio_is_null_client(socket_data *server) {
233232
rust_task *task = rust_scheduler::get_task();
234233
LOG_UPCALL_ENTRY(task);
235234
return server == NULL;
@@ -242,7 +241,7 @@ static void connection_complete(uv_connect_t *req, int status) {
242241
free(req);
243242
}
244243

245-
extern "C" CDECL void aio_connect(void *, const char *host, int port,
244+
extern "C" CDECL void aio_connect(const char *host, int port,
246245
chan_handle *_chan) {
247246
rust_task *task = rust_scheduler::get_task();
248247
LOG_UPCALL_ENTRY(task);
@@ -266,7 +265,7 @@ extern "C" CDECL void aio_connect(void *, const char *host, int port,
266265
}
267266
free(req);
268267
oom_req:
269-
aio_close_socket(task, client);
268+
aio_close_socket(client);
270269
oom_client:
271270
chan->deref();
272271
task->fail();
@@ -281,7 +280,7 @@ static void write_complete(uv_write_t *req, int status) {
281280
free(req);
282281
}
283282

284-
extern "C" CDECL void aio_writedata(void *, socket_data *data, char *buf,
283+
extern "C" CDECL void aio_writedata(socket_data *data, char *buf,
285284
size_t size, chan_handle *_chan) {
286285
rust_task *task = rust_scheduler::get_task();
287286
LOG_UPCALL_ENTRY(task);
@@ -314,8 +313,7 @@ extern "C" CDECL void aio_writedata(void *, socket_data *data, char *buf,
314313
task->fail();
315314
}
316315

317-
extern "C" CDECL void aio_read(void *, socket_data *data,
318-
chan_handle *_chan) {
316+
extern "C" CDECL void aio_read(socket_data *data, chan_handle *_chan) {
319317
rust_task *task = rust_scheduler::get_task();
320318
LOG_UPCALL_ENTRY(task);
321319
rust_chan *reader = task->get_chan_by_handle(_chan);

0 commit comments

Comments
 (0)