about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorDonovan Preston <donovanpreston@gmail.com>2012-01-27 14:04:13 -0800
committerDonovan Preston <donovanpreston@gmail.com>2012-01-27 14:04:13 -0800
commit3d76922f973caa358cf803d5539dbfadeb3ca830 (patch)
treecf3dfdd5ba09ad917ba1a5d8e84e147d0b4dff6d /src/libstd
parente48bf6f3f4d1ca07f0c2820c6cfaad275bc106ac (diff)
downloadrust-3d76922f973caa358cf803d5539dbfadeb3ca830.tar.gz
rust-3d76922f973caa358cf803d5539dbfadeb3ca830.zip
Implement timers.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/uvtmp.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/libstd/uvtmp.rs b/src/libstd/uvtmp.rs
index fb9df4bfbd3..e1d155e7c16 100644
--- a/src/libstd/uvtmp.rs
+++ b/src/libstd/uvtmp.rs
@@ -27,6 +27,11 @@ native mod rustrt {
         thread: thread,
         req_id: u32,
         chan: comm::chan<iomsg>);
+    fn rust_uvtmp_timer(
+        thread: thread,
+        timeout: u32,
+        req_id: u32,
+        chan: comm::chan<iomsg>);
     fn rust_uvtmp_delete_buf(buf: *u8);
     fn rust_uvtmp_get_req_id(cd: connect_data) -> u32;
 }
@@ -39,7 +44,9 @@ enum iomsg {
     whatever,
     connected(connect_data),
     wrote(connect_data),
-    read(connect_data, *u8, ctypes::ssize_t)
+    read(connect_data, *u8, ctypes::ssize_t),
+    timer(u32),
+    exit
 }
 
 fn create_thread() -> thread {
@@ -58,8 +65,7 @@ fn delete_thread(thread: thread) {
     rustrt::rust_uvtmp_delete_thread(thread)
 }
 
-fn connect(thread: thread, req_id: u32,
-           ip: str, ch: comm::chan<iomsg>) -> connect_data {
+fn connect(thread: thread, req_id: u32, ip: str, ch: comm::chan<iomsg>) -> connect_data {
     str::as_buf(ip) {|ipbuf|
         rustrt::rust_uvtmp_connect(thread, req_id, ipbuf, ch)
     }
@@ -80,6 +86,11 @@ fn read_start(thread: thread, req_id: u32,
     rustrt::rust_uvtmp_read_start(thread, req_id, chan);
 }
 
+fn timer_start(thread: thread, timeout: u32, req_id: u32,
+              chan: comm::chan<iomsg>) {
+    rustrt::rust_uvtmp_timer(thread, timeout, req_id, chan);
+}
+
 fn delete_buf(buf: *u8) {
     rustrt::rust_uvtmp_delete_buf(buf);
 }
@@ -106,7 +117,7 @@ fn test_connect() {
     connect(thread, 0u32, "74.125.224.146", chan);
     alt comm::recv(port) {
       connected(cd) {
-        close_connection(thread, 0u32);
+        close_connection(thread, cd);
       }
     }
     join_thread(thread);
@@ -123,10 +134,10 @@ fn test_http() {
     connect(thread, 0u32, "74.125.224.146", chan);
     alt comm::recv(port) {
       connected(cd) {
-        write(thread, 0u32, str::bytes("GET / HTTP/1.0\n\n"), chan);
+        write(thread, cd, str::bytes("GET / HTTP/1.0\n\n"), chan);
         alt comm::recv(port) {
           wrote(cd) {
-            read_start(thread, 0u32, chan);
+            read_start(thread, cd, chan);
             let keep_going = true;
             while keep_going {
                 alt comm::recv(port) {
@@ -146,7 +157,7 @@ fn test_http() {
                   }
                 }
             }
-            close_connection(thread, 0u32);
+            close_connection(thread, cd);
           }
         }
       }