std: several minor cleanups wrt codereview.. see extended comments

* there are a few places where I was experimenting w/ using `alt` in places
where `if`/`else` would've sufficed. don't drink the koolaid!
* I had an unneeded `else` structure (the `if` branch that preceeded
concluded with a `fail` statement.. I added the `fail` later in the dev
cycle for this branch, so I forgot to remove the `else` after doing so)
* consistent wrt `prop_name: value` vs. `prop_name : value` in record decl
and initialization
* change an `alt` exp on an `ip_addr` to actually be exhaustive,
instead of using a catch-all clause
This commit is contained in:
Jeff Olson 2012-05-21 06:45:18 -07:00 committed by Brian Anderson
parent 7de1a68217
commit 9b10359041

View File

@ -107,9 +107,9 @@ fn connect(input_ip: ip::ip_addr, port: uint)
let socket_data = @{ let socket_data = @{
reader_po: reader_po, reader_po: reader_po,
reader_ch: comm::chan(reader_po), reader_ch: comm::chan(reader_po),
stream_handle_ptr : stream_handle_ptr, stream_handle_ptr: stream_handle_ptr,
connect_req : uv::ll::connect_t(), connect_req: uv::ll::connect_t(),
write_req : uv::ll::write_t(), write_req: uv::ll::write_t(),
hl_loop: hl_loop hl_loop: hl_loop
}; };
let socket_data_ptr = ptr::addr_of(*socket_data); let socket_data_ptr = ptr::addr_of(*socket_data);
@ -523,13 +523,14 @@ net::tcp::listen(remote_ip, remote_port, backlog) {|new_conn, kill_ch|
let cont_ch = comm::chan(cont_po); let cont_ch = comm::chan(cont_po);
task::spawn {|| task::spawn {||
let accept_result = net::tcp::accept(new_conn); let accept_result = net::tcp::accept(new_conn);
alt accept_result.is_failure() { if accept_result.is_failure() {
false { comm::send(cont_ch, result::get_err(accept_result)); } comm::send(cont_ch, result::get_err(accept_result));
true { // fail?
}
else {
let sock = result::get(accept_result); let sock = result::get(accept_result);
comm::send(cont_ch, true); comm::send(cont_ch, true);
// do work here // do work here
}
} }
}; };
alt comm::recv(cont_po) { alt comm::recv(cont_po) {
@ -841,8 +842,7 @@ crust fn tcp_lfc_on_connection_cb(handle: *uv::ll::uv_tcp_t,
let server_data_ptr = uv::ll::get_data_for_uv_handle(handle) let server_data_ptr = uv::ll::get_data_for_uv_handle(handle)
as *tcp_listen_fc_data; as *tcp_listen_fc_data;
let kill_ch = (*server_data_ptr).kill_ch; let kill_ch = (*server_data_ptr).kill_ch;
alt (*server_data_ptr).active { if (*server_data_ptr).active {
true {
alt status { alt status {
0i32 { 0i32 {
let new_conn = new_tcp_conn(handle); let new_conn = new_tcp_conn(handle);
@ -856,9 +856,6 @@ crust fn tcp_lfc_on_connection_cb(handle: *uv::ll::uv_tcp_t,
(*server_data_ptr).active = false; (*server_data_ptr).active = false;
} }
} }
}
_ {
}
} }
} }
@ -1101,7 +1098,7 @@ fn ipv4_ip_addr_to_sockaddr_in(input_ip: ip::ip_addr,
ip::ipv4(_,_,_,_) { ip::ipv4(_,_,_,_) {
uv::ll::ip4_addr(ip::format_addr(input_ip), port as int) uv::ll::ip4_addr(ip::format_addr(input_ip), port as int)
} }
_ { ip::ipv6(_,_,_,_,_,_,_,_) {
fail "FIXME ipv6 not yet supported"; fail "FIXME ipv6 not yet supported";
} }
} }
@ -1324,24 +1321,22 @@ mod test {
err_data.err_name, err_data.err_msg)); err_data.err_name, err_data.err_msg));
fail "couldn't recv new conn"; fail "couldn't recv new conn";
} }
else { let sock = result::unwrap(new_conn_result);
let sock = result::unwrap(new_conn_result); log(debug, "SERVER: successfully accepted"+
log(debug, "SERVER: successfully accepted"+ "connection!");
"connection!"); let received_req_bytes =
let received_req_bytes = tcp_read_single(sock);
tcp_read_single(sock); alt received_req_bytes {
alt received_req_bytes { result::ok(data) {
result::ok(data) { server_ch.send(
server_ch.send( str::from_bytes(data));
str::from_bytes(data)); log(debug, "SERVER: before write");
log(debug, "SERVER: before write"); tcp_write_single(sock, str::bytes(resp));
tcp_write_single(sock, str::bytes(resp)); log(debug, "SERVER: after write.. die");
log(debug, "SERVER: after write.. die"); }
} result::err(err_data) {
result::err(err_data) { server_ch.send("");
server_ch.send(""); }
}
}
} }
}; };
let ret_val = server_ch.recv(); let ret_val = server_ch.recv();