From 062ac8cb97fef80a370ef884c468c66c4c9d30e3 Mon Sep 17 00:00:00 2001 From: a_m0d Date: Wed, 7 Nov 2012 23:49:01 -0500 Subject: [PATCH] Fix whitespace issues from previous commits. Also added test for #3891. --- src/libstd/net_tcp.rs | 50 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 0131c482f58..ea77949a459 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -811,7 +811,7 @@ impl TcpSocketBuf: io::Reader { } fn read_byte() -> int { let mut bytes = ~[0]; - if self.read(bytes, 1u) == 0 { + if self.read(bytes, 1u) == 0 { if self.end_of_stream { -1 } else { @@ -1280,7 +1280,10 @@ mod test { fn test_gl_tcp_ipv4_server_client_reader_writer() { impl_gl_tcp_ipv4_server_client_reader_writer(); } - + #[test] + fn test_tcp_socket_impl_reader_handles_eof() { + impl_tcp_socket_impl_reader_handles_eof(); + } } #[cfg(target_arch="x86")] mod impl32 { @@ -1553,6 +1556,49 @@ mod test { */ } + fn impl_tcp_socket_impl_reader_handles_eof() { + use io::{Reader,ReaderUtil}; + let hl_loop = uv::global_loop::get(); + let server_ip = ~"127.0.0.1"; + let server_port = 10041u; + let expected_req = ~"GET /"; + let expected_resp = ~"A string\nwith multiple lines\n"; + + let server_result_po = core::comm::Port::<~str>(); + let server_result_ch = core::comm::Chan(&server_result_po); + + let cont_po = core::comm::Port::<()>(); + let cont_ch = core::comm::Chan(&cont_po); + // server + do task::spawn_sched(task::ManualThreads(1u)) { + let actual_req = do comm::listen |server_ch| { + run_tcp_test_server( + server_ip, + server_port, + expected_resp, + server_ch, + cont_ch, + hl_loop) + }; + server_result_ch.send(actual_req); + }; + core::comm::recv(cont_po); + // client + log(debug, ~"server started, firing up client.."); + let server_addr = ip::v4::parse_addr(server_ip); + let conn_result = connect(server_addr, server_port, hl_loop); + if result::is_err(&conn_result) { + assert false; + } + let sock_buf = @socket_buf(result::unwrap(move conn_result)); + buf_write(sock_buf, expected_req); + + let buf_reader = sock_buf as Reader; + let actual_response = str::from_bytes(buf_reader.read_whole_stream()); + log(debug, fmt!("Actual response: %s", actual_response)); + assert expected_resp == actual_response; + } + fn buf_write(w: &W, val: &str) { log(debug, fmt!("BUF_WRITE: val len %?", str::len(val))); do str::byte_slice(val) |b_slice| {