@@ -44,7 +44,6 @@ pub use self::process::Process;
44
44
// Native I/O implementations
45
45
pub mod file;
46
46
pub mod process;
47
- pub mod net;
48
47
49
48
type IoResult < T > = Result < T , IoError > ;
50
49
@@ -56,25 +55,12 @@ fn unimpl() -> IoError {
56
55
}
57
56
}
58
57
59
- fn translate_error ( errno : i32 , detail : bool ) -> IoError {
58
+ fn last_error ( ) -> IoError {
60
59
#[ cfg( windows) ]
61
60
fn get_err ( errno : i32 ) -> ( io:: IoErrorKind , & ' static str ) {
62
61
match errno {
63
62
libc:: EOF => ( io:: EndOfFile , "end of file" ) ,
64
- libc:: WSAECONNREFUSED => ( io:: ConnectionRefused , "connection refused" ) ,
65
- libc:: WSAECONNRESET => ( io:: ConnectionReset , "connection reset" ) ,
66
- libc:: WSAEACCES => ( io:: PermissionDenied , "permission denied" ) ,
67
- libc:: WSAEWOULDBLOCK =>
68
- ( io:: ResourceUnavailable , "resource temporarily unavailable" ) ,
69
- libc:: WSAENOTCONN => ( io:: NotConnected , "not connected" ) ,
70
- libc:: WSAECONNABORTED => ( io:: ConnectionAborted , "connection aborted" ) ,
71
- libc:: WSAEADDRNOTAVAIL => ( io:: ConnectionRefused , "address not available" ) ,
72
- libc:: WSAEADDRINUSE => ( io:: ConnectionRefused , "address in use" ) ,
73
-
74
- x => {
75
- debug ! ( "ignoring {}: {}" , x, os:: last_os_error( ) ) ;
76
- ( io:: OtherIoError , "unknown error" )
77
- }
63
+ _ => ( io:: OtherIoError , "unknown error" ) ,
78
64
}
79
65
}
80
66
@@ -83,38 +69,24 @@ fn translate_error(errno: i32, detail: bool) -> IoError {
83
69
// XXX: this should probably be a bit more descriptive...
84
70
match errno {
85
71
libc:: EOF => ( io:: EndOfFile , "end of file" ) ,
86
- libc:: ECONNREFUSED => ( io:: ConnectionRefused , "connection refused" ) ,
87
- libc:: ECONNRESET => ( io:: ConnectionReset , "connection reset" ) ,
88
- libc:: EPERM | libc:: EACCES =>
89
- ( io:: PermissionDenied , "permission denied" ) ,
90
- libc:: EPIPE => ( io:: BrokenPipe , "broken pipe" ) ,
91
- libc:: ENOTCONN => ( io:: NotConnected , "not connected" ) ,
92
- libc:: ECONNABORTED => ( io:: ConnectionAborted , "connection aborted" ) ,
93
- libc:: EADDRNOTAVAIL => ( io:: ConnectionRefused , "address not available" ) ,
94
- libc:: EADDRINUSE => ( io:: ConnectionRefused , "address in use" ) ,
95
72
96
73
// These two constants can have the same value on some systems, but
97
74
// different values on others, so we can't use a match clause
98
75
x if x == libc:: EAGAIN || x == libc:: EWOULDBLOCK =>
99
76
( io:: ResourceUnavailable , "resource temporarily unavailable" ) ,
100
77
101
- x => {
102
- debug ! ( "ignoring {}: {}" , x, os:: last_os_error( ) ) ;
103
- ( io:: OtherIoError , "unknown error" )
104
- }
78
+ _ => ( io:: OtherIoError , "unknown error" ) ,
105
79
}
106
80
}
107
81
108
- let ( kind, desc) = get_err ( errno) ;
82
+ let ( kind, desc) = get_err ( os :: errno ( ) as i32 ) ;
109
83
IoError {
110
84
kind : kind,
111
85
desc : desc,
112
- detail : if detail { Some ( os:: last_os_error ( ) ) } else { None } ,
86
+ detail : Some ( os:: last_os_error ( ) )
113
87
}
114
88
}
115
89
116
- fn last_error ( ) -> IoError { translate_error ( os:: errno ( ) as i32 , true ) }
117
-
118
90
// unix has nonzero values as errors
119
91
fn mkerr_libc ( ret : libc:: c_int ) -> IoResult < ( ) > {
120
92
if ret != 0 {
@@ -134,37 +106,17 @@ fn mkerr_winbool(ret: libc::c_int) -> IoResult<()> {
134
106
}
135
107
}
136
108
137
- #[ cfg( unix) ]
138
- fn retry ( f: || -> libc:: c_int) -> IoResult < libc:: c_int > {
139
- loop {
140
- match f ( ) {
141
- -1 if os:: errno ( ) as int == libc:: EINTR as int => { }
142
- -1 => return Err ( last_error ( ) ) ,
143
- n => return Ok ( n) ,
144
- }
145
- }
146
- }
147
-
148
109
/// Implementation of rt::rtio's IoFactory trait to generate handles to the
149
110
/// native I/O functionality.
150
- pub struct IoFactory {
151
- priv cannot_construct_outside_of_this_module : ( )
152
- }
153
-
154
- impl IoFactory {
155
- pub fn new ( ) -> IoFactory {
156
- net:: init ( ) ;
157
- IoFactory { cannot_construct_outside_of_this_module : ( ) }
158
- }
159
- }
111
+ pub struct IoFactory ;
160
112
161
113
impl rtio:: IoFactory for IoFactory {
162
114
// networking
163
- fn tcp_connect ( & mut self , addr : SocketAddr ) -> IoResult < ~RtioTcpStream > {
164
- net :: TcpStream :: connect ( addr ) . map ( |s| ~s as ~ RtioTcpStream )
115
+ fn tcp_connect ( & mut self , _addr : SocketAddr ) -> IoResult < ~RtioTcpStream > {
116
+ Err ( unimpl ( ) )
165
117
}
166
- fn tcp_bind ( & mut self , addr : SocketAddr ) -> IoResult < ~RtioTcpListener > {
167
- net :: TcpListener :: bind ( addr ) . map ( |s| ~s as ~ RtioTcpListener )
118
+ fn tcp_bind ( & mut self , _addr : SocketAddr ) -> IoResult < ~RtioTcpListener > {
119
+ Err ( unimpl ( ) )
168
120
}
169
121
fn udp_bind ( & mut self , _addr : SocketAddr ) -> IoResult < ~RtioUdpSocket > {
170
122
Err ( unimpl ( ) )
@@ -252,7 +204,9 @@ impl rtio::IoFactory for IoFactory {
252
204
}
253
205
fn tty_open ( & mut self , fd : c_int , _readable : bool ) -> IoResult < ~RtioTTY > {
254
206
if unsafe { libc:: isatty ( fd) } != 0 {
255
- Ok ( ~file:: FileDesc :: new ( fd, true ) as ~RtioTTY )
207
+ // Don't ever close the stdio file descriptors, nothing good really
208
+ // comes of that.
209
+ Ok ( ~file:: FileDesc :: new ( fd, fd > libc:: STDERR_FILENO ) as ~RtioTTY )
256
210
} else {
257
211
Err ( IoError {
258
212
kind : io:: MismatchedFileTypeForOperation ,
0 commit comments