@@ -48,11 +48,13 @@ pub fn TcpSocket(socket_data: @TcpSocketData) -> TcpSocket {
48
48
*/
49
49
struct TcpSocketBuf {
50
50
data : @TcpBufferedSocketData ,
51
+ mut end_of_stream : bool ,
51
52
}
52
53
53
54
pub fn TcpSocketBuf ( data : @TcpBufferedSocketData ) -> TcpSocketBuf {
54
55
TcpSocketBuf {
55
- data : data
56
+ data : data,
57
+ end_of_stream : false
56
58
}
57
59
}
58
60
@@ -782,6 +784,7 @@ impl TcpSocketBuf: io::Reader {
782
784
let err_data = read_result. get_err ( ) ;
783
785
784
786
if err_data. err_name == ~"EOF " {
787
+ self . end_of_stream = true ;
785
788
break ;
786
789
} else {
787
790
debug ! ( "ERROR sock_buf as io::reader.read err %? %?" ,
@@ -808,13 +811,21 @@ impl TcpSocketBuf: io::Reader {
808
811
}
809
812
fn read_byte ( ) -> int {
810
813
let mut bytes = ~[ 0 ] ;
811
- if self . read ( bytes, 1 u) == 0 { fail } else { bytes[ 0 ] as int }
814
+ if self . read ( bytes, 1 u) == 0 {
815
+ if self . end_of_stream {
816
+ -1
817
+ } else {
818
+ fail
819
+ }
820
+ } else {
821
+ bytes[ 0 ] as int
822
+ }
812
823
}
813
824
fn unread_byte ( amt : int ) {
814
825
self . data . buf . unshift ( amt as u8 ) ;
815
826
}
816
827
fn eof ( ) -> bool {
817
- false // noop
828
+ self . end_of_stream
818
829
}
819
830
fn seek ( dist : int , seek : io:: SeekStyle ) {
820
831
log ( debug, fmt ! ( "tcp_socket_buf seek stub %? %?" , dist, seek) ) ;
@@ -871,7 +882,8 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) unsafe {
871
882
uv:: ll:: close ( stream_handle_ptr, tcp_socket_dtor_close_cb) ;
872
883
} ;
873
884
core:: comm:: recv ( closed_po) ;
874
- log ( debug, fmt ! ( "about to free socket_data at %?" , socket_data) ) ;
885
+ //the line below will most likely crash
886
+ //log(debug, fmt!("about to free socket_data at %?", socket_data));
875
887
rustrt:: rust_uv_current_kernel_free ( stream_handle_ptr
876
888
as * libc:: c_void ) ;
877
889
log ( debug, ~"exiting dtor for tcp_socket") ;
0 commit comments