@@ -22,8 +22,7 @@ use std::time::{Duration, Instant};
2222#[ cfg( feature = "unix" ) ]
2323use std:: os:: unix:: net:: { UnixDatagram , UnixListener , UnixStream } ;
2424
25- use libc:: { self , c_void, c_int} ;
26- use libc:: { sockaddr, socklen_t, ssize_t} ;
25+ use libc:: { self , c_void, c_int, socklen_t, ssize_t} ;
2726
2827cfg_if ! {
2928 if #[ cfg( any( target_os = "dragonfly" , target_os = "freebsd" ,
@@ -184,10 +183,14 @@ impl Socket {
184183 }
185184 0 => return Err ( io:: Error :: new ( io:: ErrorKind :: TimedOut , "connection timed out" ) ) ,
186185 _ => {
187- if pollfd. revents & libc:: POLLOUT == 0 {
188- if let Some ( e) = self . take_error ( ) ? {
189- return Err ( e) ;
190- }
186+ // linux returns POLLOUT|POLLERR|POLLHUP for refused connections (!), so look
187+ // for POLLHUP rather than read readiness
188+ if pollfd. revents & libc:: POLLHUP != 0 {
189+ let e = self . take_error ( ) ?
190+ . unwrap_or_else ( || {
191+ io:: Error :: new ( io:: ErrorKind :: Other , "no error set after POLLHUP" )
192+ } ) ;
193+ return Err ( e) ;
191194 }
192195 return Ok ( ( ) ) ;
193196 }
@@ -256,7 +259,7 @@ impl Socket {
256259 let mut socket = None ;
257260 #[ cfg( target_os = "linux" ) ] {
258261 weak ! {
259- fn accept4( c_int, * mut sockaddr, * mut socklen_t, c_int) -> c_int
262+ fn accept4( c_int, * mut libc :: sockaddr, * mut socklen_t, c_int) -> c_int
260263 }
261264 if let Some ( f) = accept4. get ( ) {
262265 let res = cvt_r ( || unsafe {
0 commit comments