提交 59a592f4 编写于 作者: A a_m0d

Add end_of_file handling to TcpBufferedSocket.

This fixes #3891.

Also removed debug!(...) statement from socket destructor which causes a
crash when the logging level is set to debug.
上级 53ec6c3f
......@@ -48,11 +48,13 @@ pub fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket {
*/
struct TcpSocketBuf {
data: @TcpBufferedSocketData,
mut end_of_stream: bool,
}
pub fn TcpSocketBuf(data: @TcpBufferedSocketData) -> TcpSocketBuf {
TcpSocketBuf {
data: data
data: data,
end_of_stream: false
}
}
......@@ -782,6 +784,7 @@ fn read(buf: &[mut u8], len: uint) -> uint {
let err_data = read_result.get_err();
if err_data.err_name == ~"EOF" {
self.end_of_stream = true;
break;
} else {
debug!("ERROR sock_buf as io::reader.read err %? %?",
......@@ -808,13 +811,21 @@ fn read(buf: &[mut u8], len: uint) -> uint {
}
fn read_byte() -> int {
let mut bytes = ~[0];
if self.read(bytes, 1u) == 0 { fail } else { bytes[0] as int }
if self.read(bytes, 1u) == 0 {
if self.end_of_stream {
-1
} else {
fail
}
} else {
bytes[0] as int
}
}
fn unread_byte(amt: int) {
self.data.buf.unshift(amt as u8);
}
fn eof() -> bool {
false // noop
self.end_of_stream
}
fn seek(dist: int, seek: io::SeekStyle) {
log(debug, fmt!("tcp_socket_buf seek stub %? %?", dist, seek));
......@@ -871,7 +882,8 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) unsafe {
uv::ll::close(stream_handle_ptr, tcp_socket_dtor_close_cb);
};
core::comm::recv(closed_po);
log(debug, fmt!("about to free socket_data at %?", socket_data));
//the line below will most likely crash
//log(debug, fmt!("about to free socket_data at %?", socket_data));
rustrt::rust_uv_current_kernel_free(stream_handle_ptr
as *libc::c_void);
log(debug, ~"exiting dtor for tcp_socket");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册