diff options
| author | Eric Holk <eholk@mozilla.com> | 2011-08-15 16:54:02 -0700 |
|---|---|---|
| committer | Eric Holk <eholk@mozilla.com> | 2011-08-16 09:36:29 -0700 |
| commit | cf2def46c120d8d6ef8a98571a39bef478c8c2a9 (patch) | |
| tree | 902078db51847e2c3badb941dcbceeb5216d866f /src/rt | |
| parent | e33af7e0b505de6d7c754d2ead26c9ee2bc8974e (diff) | |
| download | rust-cf2def46c120d8d6ef8a98571a39bef478c8c2a9.tar.gz rust-cf2def46c120d8d6ef8a98571a39bef478c8c2a9.zip | |
Removed trans_comm.rs from the compiler. Updating aio/sio to work with the new chan and port system, started on a networking module for the standard library.
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/memory_region.cpp | 2 | ||||
| -rw-r--r-- | src/rt/rust_builtin.cpp | 5 | ||||
| -rw-r--r-- | src/rt/rust_chan.h | 6 | ||||
| -rw-r--r-- | src/rt/rust_internal.h | 1 | ||||
| -rw-r--r-- | src/rt/rust_task.cpp | 11 | ||||
| -rw-r--r-- | src/rt/rust_task.h | 2 | ||||
| -rw-r--r-- | src/rt/rust_uv.cpp | 32 | ||||
| -rw-r--r-- | src/rt/rustrt.def.in | 1 |
8 files changed, 47 insertions, 13 deletions
diff --git a/src/rt/memory_region.cpp b/src/rt/memory_region.cpp index 7b38f65caaf..d9755c55888 100644 --- a/src/rt/memory_region.cpp +++ b/src/rt/memory_region.cpp @@ -4,7 +4,7 @@ // NB: please do not commit code with this uncommented. It's // hugely expensive and should only be used as a last resort. // -// #define TRACK_ALLOCATIONS +#define TRACK_ALLOCATIONS #define MAGIC 0xbadc0ffe diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index ef236247396..2675368fd88 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -775,11 +775,6 @@ migrate_alloc(rust_task *task, void *alloc, rust_task_id tid) { } } -extern "C" CDECL rust_chan * -clone_chan(rust_task *task, rust_chan *chan) { - return chan->clone(task); -} - // defined in rust_task.cpp extern size_t g_custom_min_stack_size; extern "C" CDECL void diff --git a/src/rt/rust_chan.h b/src/rt/rust_chan.h index 9dbd9337a18..99ace5c5294 100644 --- a/src/rt/rust_chan.h +++ b/src/rt/rust_chan.h @@ -25,6 +25,12 @@ public: rust_chan *clone(rust_task *target); }; +// Corresponds to the rust chan (currently _chan) type. +struct chan_handle { + rust_task_id task; + rust_port_id port; +}; + // // Local Variables: // mode: C++ diff --git a/src/rt/rust_internal.h b/src/rt/rust_internal.h index 5045b395477..65805deefb8 100644 --- a/src/rt/rust_internal.h +++ b/src/rt/rust_internal.h @@ -56,6 +56,7 @@ struct rust_task; class rust_log; class rust_port; class rust_chan; +struct chan_handle; struct rust_token; class rust_kernel; class rust_crate_cache; diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index 148996f0008..8ef83488513 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -527,6 +527,17 @@ rust_port *rust_task::get_port_by_id(rust_port_id id) { return port; } +rust_chan *rust_task::get_chan_by_handle(chan_handle *handle) { + rust_task *target_task = kernel->get_task_by_id(handle->task); + if(target_task) { + rust_port *port = target_task->get_port_by_id(handle->port); + target_task->deref(); + port->remote_chan->ref(); + return port->remote_chan; + } + return NULL; +} + // // Local Variables: // mode: C++ diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index c757a9e69e1..aafc0e1abb7 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -173,6 +173,8 @@ rust_task : public kernel_owned<rust_task>, rust_cond // Use this function sparingly. Depending on the ref count is generally // not at all safe. intptr_t get_ref_count() const { return ref_count; } + + rust_chan *get_chan_by_handle(chan_handle *handle); }; // diff --git a/src/rt/rust_uv.cpp b/src/rt/rust_uv.cpp index 2d4d88b96cd..b792121de35 100644 --- a/src/rt/rust_uv.cpp +++ b/src/rt/rust_uv.cpp @@ -170,8 +170,10 @@ static void new_connection(uv_handle_t *socket, int status) { } extern "C" CDECL socket_data *aio_serve(rust_task *task, const char *ip, - int port, rust_chan *chan) { + int port, chan_handle *_chan) { LOG_UPCALL_ENTRY(task); + rust_chan *chan = task->get_chan_by_handle(_chan); + if(!chan) return NULL; struct sockaddr_in addr = uv_ip4_addr(const_cast<char*>(ip), port); socket_data *server = make_socket(iotask, chan); if (!server) @@ -179,10 +181,13 @@ extern "C" CDECL socket_data *aio_serve(rust_task *task, const char *ip, if (uv_tcp_bind(&server->socket, addr) || uv_tcp_listen(&server->socket, 128, new_connection)) { aio_close_socket(task, server); + chan->deref(); return NULL; } + chan->deref(); return server; oom: + chan->deref(); task->fail(); return NULL; } @@ -218,8 +223,10 @@ extern "C" CDECL void aio_close_socket(rust_task *task, socket_data *client) { } extern "C" CDECL void aio_close_server(rust_task *task, socket_data *server, - rust_chan *chan) { + chan_handle *_chan) { LOG_UPCALL_ENTRY(task); + rust_chan *chan = task->get_chan_by_handle(_chan); + if(!chan) return; // XXX: hax until rust_task::kill // send null and the receiver knows to call back into native code to check void* null_client = NULL; @@ -227,6 +234,7 @@ extern "C" CDECL void aio_close_server(rust_task *task, socket_data *server, server->chan->deref(); server->chan = chan->clone(iotask); aio_close_socket(task, server); + chan->deref(); } extern "C" CDECL bool aio_is_null_client(rust_task *task, @@ -243,8 +251,10 @@ static void connection_complete(request *req, int status) { } extern "C" CDECL void aio_connect(rust_task *task, const char *host, - int port, rust_chan *chan) { + int port, chan_handle *_chan) { LOG_UPCALL_ENTRY(task); + rust_chan *chan = task->get_chan_by_handle(_chan); + if(!chan) return; struct sockaddr_in addr = uv_ip4_addr(const_cast<char*>(host), port); request *req; socket_data *client = make_socket(iotask, NULL); @@ -257,11 +267,13 @@ extern "C" CDECL void aio_connect(rust_task *task, const char *host, goto oom_req; } if (0 == uv_tcp_connect(req, addr)) { - return; + chan->deref(); + return; } oom_req: aio_close_socket(task, client); oom_client: + chan->deref(); task->fail(); return; } @@ -274,8 +286,11 @@ static void write_complete(request *req, int status) { } extern "C" CDECL void aio_writedata(rust_task *task, socket_data *data, - char *buf, size_t size, rust_chan *chan) { + char *buf, size_t size, + chan_handle *_chan) { LOG_UPCALL_ENTRY(task); + rust_chan *chan = task->get_chan_by_handle(_chan); + if(!chan) return; // uv_buf_t is defined backwards on win32... // maybe an indication we shouldn't be building directly? @@ -294,15 +309,20 @@ extern "C" CDECL void aio_writedata(rust_task *task, socket_data *data, delete req; goto fail; } + chan->deref(); return; fail: + chan->deref(); task->fail(); } extern "C" CDECL void aio_read(rust_task *task, socket_data *data, - rust_chan *reader) { + chan_handle *_chan) { LOG_UPCALL_ENTRY(task); + rust_chan *reader = task->get_chan_by_handle(_chan); + if(!reader) return; I(task->sched, data->reader == NULL); data->reader = reader->clone(iotask); uv_read_start((uv_stream_t*)&data->socket, alloc_buffer, read_progress); + reader->deref(); } diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index ccc190077d8..ce8434240d5 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -12,7 +12,6 @@ align_of chan_id_send chan_send check_claims -clone_chan debug_box debug_fn debug_obj |
