about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authora_m0d <damien.schoof@gmail.com>2012-11-01 23:29:46 -0400
committera_m0d <damien.schoof@gmail.com>2012-11-06 19:12:26 -0500
commit59a592f4c43a1a7a1814951ecc5f41896cabd05d (patch)
tree51f32ade587438c1dda83094dd921ce1fcd4204c /src/libstd
parent53ec6c3f9b495dd930cd061784251534bef58d74 (diff)
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.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/net_tcp.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs
index 942d52a3ad6..a2c3c77eba3 100644
--- a/src/libstd/net_tcp.rs
+++ b/src/libstd/net_tcp.rs
@@ -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 @@ impl TcpSocketBuf: io::Reader {
                 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 @@ impl TcpSocketBuf: io::Reader {
     }
     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");