提交 da2ac908 编写于 作者: P Patrick Walton

libstd: Remove mutable fields from fileinput and net_tcp

上级 5a65f51d
...@@ -145,7 +145,7 @@ struct FileInput_ { ...@@ -145,7 +145,7 @@ struct FileInput_ {
// "self.fi." -> "self." and renaming FileInput_. Documentation above // "self.fi." -> "self." and renaming FileInput_. Documentation above
// will likely have to be updated to use `let mut in = ...`. // will likely have to be updated to use `let mut in = ...`.
pub struct FileInput { pub struct FileInput {
priv mut fi: FileInput_ priv fi: @mut FileInput_
} }
impl FileInput { impl FileInput {
...@@ -170,7 +170,7 @@ pub fn from_vec(files: ~[Option<Path>]) -> FileInput { ...@@ -170,7 +170,7 @@ pub fn from_vec(files: ~[Option<Path>]) -> FileInput {
pub fn from_vec_raw(files: ~[Option<Path>]) pub fn from_vec_raw(files: ~[Option<Path>])
-> FileInput { -> FileInput {
FileInput{ FileInput{
fi: FileInput_ { fi: @mut FileInput_ {
files: files, files: files,
current_reader: None, current_reader: None,
state: FileInputState { state: FileInputState {
......
...@@ -71,14 +71,14 @@ pub fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket { ...@@ -71,14 +71,14 @@ pub fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket {
* satisfy both the `io::Reader` and `io::Writer` traits. * satisfy both the `io::Reader` and `io::Writer` traits.
*/ */
pub struct TcpSocketBuf { pub struct TcpSocketBuf {
data: @TcpBufferedSocketData, data: @mut TcpBufferedSocketData,
mut end_of_stream: bool end_of_stream: @mut bool
} }
pub fn TcpSocketBuf(data: @TcpBufferedSocketData) -> TcpSocketBuf { pub fn TcpSocketBuf(data: @mut TcpBufferedSocketData) -> TcpSocketBuf {
TcpSocketBuf { TcpSocketBuf {
data: data, data: data,
end_of_stream: false end_of_stream: @mut false
} }
} }
...@@ -670,7 +670,7 @@ fn listen_common(host_ip: ip::IpAddr, ...@@ -670,7 +670,7 @@ fn listen_common(host_ip: ip::IpAddr,
&ip::Ipv4(_) => { false } &ip::Ipv4(_) => { false }
&ip::Ipv6(_) => { true } &ip::Ipv6(_) => { true }
}, },
mut active: true active: @mut true
}; };
let server_data_ptr: *TcpListenFcData = &server_data; let server_data_ptr: *TcpListenFcData = &server_data;
...@@ -751,7 +751,7 @@ fn listen_common(host_ip: ip::IpAddr, ...@@ -751,7 +751,7 @@ fn listen_common(host_ip: ip::IpAddr,
debug!( debug!(
"tcp::listen post-kill recv hl interact %?", "tcp::listen post-kill recv hl interact %?",
loop_ptr); loop_ptr);
(*server_data_ptr).active = false; *(*server_data_ptr).active = false;
uv::ll::close(server_stream_ptr, tcp_lfc_close_cb); uv::ll::close(server_stream_ptr, tcp_lfc_close_cb);
} }
}; };
...@@ -782,7 +782,7 @@ fn listen_common(host_ip: ip::IpAddr, ...@@ -782,7 +782,7 @@ fn listen_common(host_ip: ip::IpAddr,
debug!( debug!(
"tcp::listen post-kill recv hl interact %?", "tcp::listen post-kill recv hl interact %?",
loop_ptr); loop_ptr);
(*server_data_ptr).active = false; *(*server_data_ptr).active = false;
uv::ll::close(server_stream_ptr, tcp_lfc_close_cb); uv::ll::close(server_stream_ptr, tcp_lfc_close_cb);
} }
}; };
...@@ -816,8 +816,8 @@ fn listen_common(host_ip: ip::IpAddr, ...@@ -816,8 +816,8 @@ fn listen_common(host_ip: ip::IpAddr,
* A buffered wrapper that you can cast as an `io::Reader` or `io::Writer` * A buffered wrapper that you can cast as an `io::Reader` or `io::Writer`
*/ */
pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf { pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf {
TcpSocketBuf(@TcpBufferedSocketData { TcpSocketBuf(@mut TcpBufferedSocketData {
sock: sock, mut buf: ~[], buf_off: 0 sock: sock, buf: ~[], buf_off: 0
}) })
} }
...@@ -902,12 +902,13 @@ fn read(&self, buf: &mut [u8], len: uint) -> uint { ...@@ -902,12 +902,13 @@ fn read(&self, buf: &mut [u8], len: uint) -> uint {
// need to read in data from the socket. Note that the internal // need to read in data from the socket. Note that the internal
// buffer is of no use anymore as we read all bytes from it, // buffer is of no use anymore as we read all bytes from it,
// so we can throw it away. // so we can throw it away.
let read_result = read(&self.data.sock, 0u); let data = &*self.data;
let read_result = read(&data.sock, 0u);
if read_result.is_err() { if read_result.is_err() {
let err_data = read_result.get_err(); let err_data = read_result.get_err();
if err_data.err_name == ~"EOF" { if err_data.err_name == ~"EOF" {
self.end_of_stream = true; *self.end_of_stream = true;
break; break;
} else { } else {
debug!("ERROR sock_buf as io::reader.read err %? %?", debug!("ERROR sock_buf as io::reader.read err %? %?",
...@@ -934,12 +935,13 @@ fn read_byte(&self) -> int { ...@@ -934,12 +935,13 @@ fn read_byte(&self) -> int {
return c as int return c as int
} }
let read_result = read(&self.data.sock, 0u); let data = &*self.data;
let read_result = read(&data.sock, 0u);
if read_result.is_err() { if read_result.is_err() {
let err_data = read_result.get_err(); let err_data = read_result.get_err();
if err_data.err_name == ~"EOF" { if err_data.err_name == ~"EOF" {
self.end_of_stream = true; *self.end_of_stream = true;
return -1 return -1
} else { } else {
debug!("ERROR sock_buf as io::reader.read err %? %?", debug!("ERROR sock_buf as io::reader.read err %? %?",
...@@ -954,7 +956,7 @@ fn read_byte(&self) -> int { ...@@ -954,7 +956,7 @@ fn read_byte(&self) -> int {
} }
} }
fn eof(&self) -> bool { fn eof(&self) -> bool {
self.end_of_stream *self.end_of_stream
} }
fn seek(&self, dist: int, seek: io::SeekStyle) { fn seek(&self, dist: int, seek: io::SeekStyle) {
debug!("tcp_socket_buf seek stub %? %?", dist, seek); debug!("tcp_socket_buf seek stub %? %?", dist, seek);
...@@ -1204,7 +1206,7 @@ struct TcpListenFcData { ...@@ -1204,7 +1206,7 @@ struct TcpListenFcData {
on_connect_cb: ~fn(*uv::ll::uv_tcp_t), on_connect_cb: ~fn(*uv::ll::uv_tcp_t),
iotask: IoTask, iotask: IoTask,
ipv6: bool, ipv6: bool,
mut active: bool, active: @mut bool,
} }
extern fn tcp_lfc_close_cb(handle: *uv::ll::uv_tcp_t) { extern fn tcp_lfc_close_cb(handle: *uv::ll::uv_tcp_t) {
...@@ -1222,7 +1224,7 @@ struct TcpListenFcData { ...@@ -1222,7 +1224,7 @@ struct TcpListenFcData {
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 *TcpListenFcData; as *TcpListenFcData;
let kill_ch = (*server_data_ptr).kill_ch.clone(); let kill_ch = (*server_data_ptr).kill_ch.clone();
if (*server_data_ptr).active { if *(*server_data_ptr).active {
match status { match status {
0i32 => ((*server_data_ptr).on_connect_cb)(handle), 0i32 => ((*server_data_ptr).on_connect_cb)(handle),
_ => { _ => {
...@@ -1230,7 +1232,7 @@ struct TcpListenFcData { ...@@ -1230,7 +1232,7 @@ struct TcpListenFcData {
kill_ch.send( kill_ch.send(
Some(uv::ll::get_last_err_data(loop_ptr) Some(uv::ll::get_last_err_data(loop_ptr)
.to_tcp_err())); .to_tcp_err()));
(*server_data_ptr).active = false; *(*server_data_ptr).active = false;
} }
} }
} }
...@@ -1430,8 +1432,8 @@ struct TcpSocketData { ...@@ -1430,8 +1432,8 @@ struct TcpSocketData {
struct TcpBufferedSocketData { struct TcpBufferedSocketData {
sock: TcpSocket, sock: TcpSocket,
mut buf: ~[u8], buf: ~[u8],
mut buf_off: uint buf_off: uint
} }
#[cfg(test)] #[cfg(test)]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册