Fix whitespace issues from previous commits.

Also added test for #3891.
This commit is contained in:
a_m0d 2012-11-07 23:49:01 -05:00
parent d42cf97bcc
commit 062ac8cb97

View File

@ -811,7 +811,7 @@ impl TcpSocketBuf: io::Reader {
} }
fn read_byte() -> int { fn read_byte() -> int {
let mut bytes = ~[0]; let mut bytes = ~[0];
if self.read(bytes, 1u) == 0 { if self.read(bytes, 1u) == 0 {
if self.end_of_stream { if self.end_of_stream {
-1 -1
} else { } else {
@ -1280,7 +1280,10 @@ mod test {
fn test_gl_tcp_ipv4_server_client_reader_writer() { fn test_gl_tcp_ipv4_server_client_reader_writer() {
impl_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")] #[cfg(target_arch="x86")]
mod impl32 { 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:io::Writer>(w: &W, val: &str) { fn buf_write<W:io::Writer>(w: &W, val: &str) {
log(debug, fmt!("BUF_WRITE: val len %?", str::len(val))); log(debug, fmt!("BUF_WRITE: val len %?", str::len(val)));
do str::byte_slice(val) |b_slice| { do str::byte_slice(val) |b_slice| {