Skip to content

Commit 397bad2

Browse files
olsonjefferybrson
authored andcommitted
---
yaml --- r: 15995 b: refs/heads/try c: 92e9e73 h: refs/heads/master i: 15993: 321e99d 15991: df8cbc6 v: v3
1 parent fea2d41 commit 397bad2

File tree

3 files changed

+56
-35
lines changed

3 files changed

+56
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: b0b175214a794a9f84f65ae8687522491f8b9c4b
5+
refs/heads/try: 92e9e736fab57a169882897337cef344a48c0c2d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libstd/net_tcp.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,18 @@ Initiate a client connection over TCP/IP
8383
8484
# Arguments
8585
86-
* ip - The IP address (versions 4 or 6) of the remote host
87-
* port - the unsigned integer of the desired remote host port
86+
* `ip` - The IP address (versions 4 or 6) of the remote host
87+
* `port` - the unsigned integer of the desired remote host port
88+
* `hl_loop` - a `uv::hl::high_level_loop` that the tcp request will run on
8889
8990
# Returns
9091
9192
A `result` that, if the operation succeeds, contains a `tcp_socket` that
9293
can be used to send and receive data to/from the remote host. In the event
9394
of failure, a `tcp_err_data` will be returned
9495
"]
95-
fn connect(input_ip: ip::ip_addr, port: uint)
96+
fn connect(input_ip: ip::ip_addr, port: uint,
97+
hl_loop: uv::hl::high_level_loop)
9698
-> result::result<tcp_socket, tcp_err_data> unsafe {
9799
let result_po = comm::port::<conn_attempt>();
98100
let closed_signal_po = comm::port::<()>();
@@ -101,7 +103,6 @@ fn connect(input_ip: ip::ip_addr, port: uint)
101103
closed_signal_ch: comm::chan(closed_signal_po)
102104
};
103105
let conn_data_ptr = ptr::addr_of(conn_data);
104-
let hl_loop = uv::global_loop::get();
105106
let reader_po = comm::port::<result::result<[u8], tcp_err_data>>();
106107
let stream_handle_ptr = malloc_uv_tcp_t();
107108
*(stream_handle_ptr as *mut uv::ll::uv_tcp_t) = uv::ll::tcp_t();
@@ -343,18 +344,19 @@ Bind to a given IP/port and listen for new connections
343344
* `port` - a uint representing the port to listen on
344345
* `backlog` - a uint representing the number of incoming connections
345346
to cache in memory
347+
* `hl_loop` - a `uv::hl::high_level_loop` that the tcp request will run on
346348
347349
# Returns
348350
349351
A `result` instance containing either a `tcp_conn_port` which can used
350352
to listen for, and accept, new connections, or a `tcp_err_data` if
351353
failure to create the tcp listener occurs
352354
"]
353-
fn new_listener(host_ip: ip::ip_addr, port: uint, backlog: uint)
355+
fn new_listener(host_ip: ip::ip_addr, port: uint, backlog: uint,
356+
hl_loop: uv::hl::high_level_loop)
354357
-> result::result<tcp_conn_port, tcp_err_data> unsafe {
355358
let stream_closed_po = comm::port::<()>();
356359
let stream_closed_ch = comm::chan(stream_closed_po);
357-
let hl_loop = uv::global_loop::get();
358360
let new_conn_po = comm::port::<result::result<*uv::ll::uv_tcp_t,
359361
tcp_err_data>>();
360362
let new_conn_ch = comm::chan(new_conn_po);
@@ -653,6 +655,7 @@ Bind to a given IP/port and listen for new connections
653655
* `port` - a uint representing the port to listen on
654656
* `backlog` - a uint representing the number of incoming connections
655657
to cache in memory
658+
* `hl_loop` - a `uv::hl::high_level_loop` that the tcp request will run on
656659
* `on_establish_cb` - a callback that is evaluated if/when the listener
657660
is successfully established. it takes no parameters
658661
* `new_connect_cb` - a callback to be evaluated, on the libuv thread,
@@ -671,6 +674,7 @@ successful/normal shutdown, and a `tcp_err_data` record in the event
671674
of listen exiting because of an error
672675
"]
673676
fn listen_for_conn(host_ip: ip::ip_addr, port: uint, backlog: uint,
677+
hl_loop: uv::hl::high_level_loop,
674678
on_establish_cb: fn~(comm::chan<option<tcp_err_data>>),
675679
new_connect_cb: fn~(tcp_new_connection,
676680
comm::chan<option<tcp_err_data>>))
@@ -680,7 +684,6 @@ fn listen_for_conn(host_ip: ip::ip_addr, port: uint, backlog: uint,
680684
let kill_ch = comm::chan(kill_po);
681685
let server_stream = uv::ll::tcp_t();
682686
let server_stream_ptr = ptr::addr_of(server_stream);
683-
let hl_loop = uv::global_loop::get();
684687
let server_data = {
685688
server_stream_ptr: server_stream_ptr,
686689
stream_closed_ch: comm::chan(stream_closed_po),
@@ -804,8 +807,9 @@ impl sock_methods for tcp_socket {
804807

805808
// shared implementation for tcp::read
806809
fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint)
807-
-> result::result<[u8],tcp_err_data> {
810+
-> result::result<[u8],tcp_err_data> unsafe {
808811
log(debug, "starting tcp::read");
812+
let hl_loop = (*socket_data).hl_loop;
809813
let rs_result = read_start_common_impl(socket_data);
810814
if result::is_failure(rs_result) {
811815
let err_data = result::get_err(rs_result);
@@ -815,7 +819,7 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint)
815819
log(debug, "tcp::read before recv_timeout");
816820
let read_result = if timeout_msecs > 0u {
817821
timer::recv_timeout(
818-
timeout_msecs, result::get(rs_result))
822+
hl_loop, timeout_msecs, result::get(rs_result))
819823
} else {
820824
some(comm::recv(result::get(rs_result)))
821825
};
@@ -1270,7 +1274,7 @@ fn ipv4_ip_addr_to_sockaddr_in(input_ip: ip::ip_addr,
12701274
}
12711275
}
12721276

1273-
//#[cfg(test)]
1277+
#[cfg(test)]
12741278
mod test {
12751279
// FIXME don't run on fbsd or linux 32 bit(#2064)
12761280
#[cfg(target_os="win32")]
@@ -1303,6 +1307,7 @@ mod test {
13031307
}
13041308
}
13051309
fn impl_gl_tcp_ipv4_server_and_client() {
1310+
let hl_loop = uv::global_loop::get();
13061311
let server_ip = "127.0.0.1";
13071312
let server_port = 8888u;
13081313
let expected_req = "ping";
@@ -1321,7 +1326,8 @@ mod test {
13211326
server_port,
13221327
expected_resp,
13231328
server_ch,
1324-
cont_ch)
1329+
cont_ch,
1330+
hl_loop)
13251331
};
13261332
server_result_ch.send(actual_req);
13271333
};
@@ -1333,7 +1339,8 @@ mod test {
13331339
server_ip,
13341340
server_port,
13351341
expected_req,
1336-
client_ch)
1342+
client_ch,
1343+
hl_loop)
13371344
};
13381345
let actual_req = comm::recv(server_result_po);
13391346
log(debug, #fmt("REQ: expected: '%s' actual: '%s'",
@@ -1344,6 +1351,7 @@ mod test {
13441351
assert str::contains(actual_resp, expected_resp);
13451352
}
13461353
fn impl_gl_tcp_ipv4_server_listener_and_client() {
1354+
let hl_loop = uv::global_loop::get();
13471355
let server_ip = "127.0.0.1";
13481356
let server_port = 8889u;
13491357
let expected_req = "ping";
@@ -1362,7 +1370,8 @@ mod test {
13621370
server_port,
13631371
expected_resp,
13641372
server_ch,
1365-
cont_ch)
1373+
cont_ch,
1374+
hl_loop)
13661375
};
13671376
server_result_ch.send(actual_req);
13681377
};
@@ -1374,7 +1383,8 @@ mod test {
13741383
server_ip,
13751384
server_port,
13761385
expected_req,
1377-
client_ch)
1386+
client_ch,
1387+
hl_loop)
13781388
};
13791389
let actual_req = comm::recv(server_result_po);
13801390
log(debug, #fmt("REQ: expected: '%s' actual: '%s'",
@@ -1387,12 +1397,14 @@ mod test {
13871397

13881398
fn run_tcp_test_server(server_ip: str, server_port: uint, resp: str,
13891399
server_ch: comm::chan<str>,
1390-
cont_ch: comm::chan<()>) -> str {
1400+
cont_ch: comm::chan<()>,
1401+
hl_loop: uv::hl::high_level_loop) -> str {
13911402

13921403
task::spawn_sched(task::manual_threads(1u)) {||
13931404
let server_ip_addr = ip::v4::parse_addr(server_ip);
13941405
let listen_result =
13951406
listen_for_conn(server_ip_addr, server_port, 128u,
1407+
hl_loop,
13961408
// on_establish_cb -- called when listener is set up
13971409
{|kill_ch|
13981410
log(debug, #fmt("establish_cb %?",
@@ -1464,12 +1476,13 @@ mod test {
14641476
fn run_tcp_test_server_listener(server_ip: str,
14651477
server_port: uint, resp: str,
14661478
server_ch: comm::chan<str>,
1467-
cont_ch: comm::chan<()>) -> str {
1479+
cont_ch: comm::chan<()>,
1480+
hl_loop: uv::hl::high_level_loop) -> str {
14681481

14691482
task::spawn_sched(task::manual_threads(1u)) {||
14701483
let server_ip_addr = ip::v4::parse_addr(server_ip);
14711484
let new_listener_result =
1472-
new_listener(server_ip_addr, server_port, 128u);
1485+
new_listener(server_ip_addr, server_port, 128u, hl_loop);
14731486
if result::is_failure(new_listener_result) {
14741487
let err_data = result::get_err(new_listener_result);
14751488
log(debug, #fmt("SERVER: exited abnormally name %s msg %s",
@@ -1512,12 +1525,13 @@ mod test {
15121525
}
15131526

15141527
fn run_tcp_test_client(server_ip: str, server_port: uint, resp: str,
1515-
client_ch: comm::chan<str>) -> str {
1528+
client_ch: comm::chan<str>,
1529+
hl_loop: uv::hl::high_level_loop) -> str {
15161530

15171531
let server_ip_addr = ip::v4::parse_addr(server_ip);
15181532

15191533
log(debug, "CLIENT: starting..");
1520-
let connect_result = connect(server_ip_addr, server_port);
1534+
let connect_result = connect(server_ip_addr, server_port, hl_loop);
15211535
if result::is_failure(connect_result) {
15221536
log(debug, "CLIENT: failed to connect");
15231537
let err_data = result::get_err(connect_result);

branches/try/src/libstd/timer.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ for *at least* that period of time.
1616
1717
# Arguments
1818
19+
* `hl_loop` - a `uv::hl::high_level_loop` that the tcp request will run on
1920
* msecs - a timeout period, in milliseconds, to wait
2021
* ch - a channel of type T to send a `val` on
2122
* val - a value of type T to send over the provided `ch`
2223
"]
23-
fn delayed_send<T: copy send>(msecs: uint, ch: comm::chan<T>, val: T) {
24+
fn delayed_send<T: send>(hl_loop: uv::hl::high_level_loop,
25+
msecs: uint, ch: comm::chan<T>, val: T) {
2426
task::spawn() {||
2527
unsafe {
2628
let timer_done_po = comm::port::<()>();
2729
let timer_done_ch = comm::chan(timer_done_po);
2830
let timer_done_ch_ptr = ptr::addr_of(timer_done_ch);
2931
let timer = uv::ll::timer_t();
3032
let timer_ptr = ptr::addr_of(timer);
31-
let hl_loop = uv::global_loop::get();
3233
uv::hl::interact(hl_loop) {|loop_ptr|
3334
let init_result = uv::ll::timer_init(loop_ptr, timer_ptr);
3435
if (init_result == 0i32) {
@@ -67,12 +68,13 @@ for *at least* that period of time.
6768
6869
# Arguments
6970
71+
* `hl_loop` - a `uv::hl::high_level_loop` that the tcp request will run on
7072
* msecs - an amount of time, in milliseconds, for the current task to block
7173
"]
72-
fn sleep(msecs: uint) {
74+
fn sleep(hl_loop: uv::hl::high_level_loop, msecs: uint) {
7375
let exit_po = comm::port::<()>();
7476
let exit_ch = comm::chan(exit_po);
75-
delayed_send(msecs, exit_ch, ());
77+
delayed_send(hl_loop, msecs, exit_ch, ());
7678
comm::recv(exit_po);
7779
}
7880

@@ -85,6 +87,7 @@ timeout. Depending on whether the provided port receives in that time period,
8587
8688
# Arguments
8789
90+
* `hl_loop` - a `uv::hl::high_level_loop` that the tcp request will run on
8891
* msecs - an mount of time, in milliseconds, to wait to receive
8992
* wait_port - a `comm::port<T>` to receive on
9093
@@ -94,12 +97,11 @@ An `option<T>` representing the outcome of the call. If the call `recv`'d on
9497
the provided port in the allotted timeout period, then the result will be a
9598
`some(T)`. If not, then `none` will be returned.
9699
"]
97-
fn recv_timeout<T: copy send>(msecs: uint, wait_po: comm::port<T>)
98-
-> option<T> {
99-
100+
fn recv_timeout<T: send>(hl_loop: uv::hl::high_level_loop,
101+
msecs: uint, wait_po: comm::port<T>) -> option<T> {
100102
let timeout_po = comm::port::<()>();
101103
let timeout_ch = comm::chan(timeout_po);
102-
delayed_send(msecs, timeout_ch, ());
104+
delayed_send(hl_loop, msecs, timeout_ch, ());
103105
either::either(
104106
{|left_val|
105107
log(debug, #fmt("recv_time .. left_val %?",
@@ -140,20 +142,23 @@ crust fn delayed_send_close_cb(handle: *uv::ll::uv_timer_t) unsafe {
140142
mod test {
141143
#[test]
142144
fn test_gl_timer_simple_sleep_test() {
143-
sleep(1u);
145+
let hl_loop = uv::global_loop::get();
146+
sleep(hl_loop, 1u);
144147
}
145148

146149
#[test]
147150
fn test_gl_timer_sleep_stress1() {
151+
let hl_loop = uv::global_loop::get();
148152
iter::repeat(200u) {||
149-
sleep(1u);
153+
sleep(hl_loop, 1u);
150154
}
151155
}
152156

153157
#[test]
154158
fn test_gl_timer_sleep_stress2() {
155159
let po = comm::port();
156160
let ch = comm::chan(po);
161+
let hl_loop = uv::global_loop::get();
157162

158163
let repeat = 20u;
159164
let spec = {
@@ -172,7 +177,7 @@ mod test {
172177
import rand::*;
173178
let rng = rng();
174179
iter::repeat(times) {||
175-
sleep(rng.next() as uint % maxms);
180+
sleep(hl_loop, rng.next() as uint % maxms);
176181
}
177182
comm::send(ch, ());
178183
}
@@ -195,6 +200,7 @@ mod test {
195200
let times = 100;
196201
let mut successes = 0;
197202
let mut failures = 0;
203+
let hl_loop = uv::global_loop::get();
198204

199205
iter::repeat(times as uint) {||
200206
task::yield();
@@ -204,10 +210,10 @@ mod test {
204210
let test_ch = comm::chan(test_po);
205211

206212
task::spawn() {||
207-
delayed_send(1u, test_ch, expected);
213+
delayed_send(hl_loop, 1u, test_ch, expected);
208214
};
209215

210-
alt recv_timeout(10u, test_po) {
216+
alt recv_timeout(hl_loop, 10u, test_po) {
211217
some(val) { assert val == expected; successes += 1; }
212218
_ { failures += 1; }
213219
};
@@ -221,17 +227,18 @@ mod test {
221227
let times = 100;
222228
let mut successes = 0;
223229
let mut failures = 0;
230+
let hl_loop = uv::global_loop::get();
224231

225232
iter::repeat(times as uint) {||
226233
let expected = rand::rng().gen_str(16u);
227234
let test_po = comm::port::<str>();
228235
let test_ch = comm::chan(test_po);
229236

230237
task::spawn() {||
231-
delayed_send(1000u, test_ch, expected);
238+
delayed_send(hl_loop, 1000u, test_ch, expected);
232239
};
233240

234-
let actual = alt recv_timeout(1u, test_po) {
241+
let actual = alt recv_timeout(hl_loop, 1u, test_po) {
235242
none { successes += 1; }
236243
_ { failures += 1; }
237244
};

0 commit comments

Comments
 (0)