@@ -285,33 +285,6 @@ impl Client {
285285 pub fn try_acquire ( & self ) -> io:: Result < Option < Acquired > > {
286286 let mut buf = [ 0 ] ;
287287
288- // On Linux, we can use preadv2 to do non-blocking read,
289- // even if `O_NONBLOCK` is not set.
290- //
291- // TODO: musl libc supports preadv2 since 1.2.5, but `libc` crate
292- // hasn't yet added it.
293- #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
294- {
295- let read = self . read ( ) . as_raw_fd ( ) ;
296- loop {
297- match non_blocking_read ( read, & mut buf) {
298- Ok ( 1 ) => return Ok ( Some ( Acquired { byte : buf[ 0 ] } ) ) ,
299- Ok ( _) => {
300- return Err ( io:: Error :: new (
301- io:: ErrorKind :: UnexpectedEof ,
302- "early EOF on jobserver pipe" ,
303- ) )
304- }
305-
306- Err ( e) if e. kind ( ) == io:: ErrorKind :: WouldBlock => return Ok ( None ) ,
307- Err ( e) if e. kind ( ) == io:: ErrorKind :: Interrupted => continue ,
308- Err ( e) if e. kind ( ) == io:: ErrorKind :: Unsupported => break ,
309-
310- Err ( err) => return Err ( err) ,
311- }
312- }
313- }
314-
315288 let ( mut fifo, is_non_blocking) = match self {
316289 Self :: Fifo {
317290 file,
@@ -580,50 +553,6 @@ extern "C" fn sigusr1_handler(
580553 // nothing to do
581554}
582555
583- // This should be available for all linux targets,
584- // though only [`non_blocking_read`] currently uses it so adding gnu cfg.
585- #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
586- fn cvt_ssize ( t : libc:: ssize_t ) -> io:: Result < libc:: ssize_t > {
587- if t == -1 {
588- Err ( io:: Error :: last_os_error ( ) )
589- } else {
590- Ok ( t)
591- }
592- }
593-
594- #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
595- fn non_blocking_read ( fd : c_int , buf : & mut [ u8 ] ) -> io:: Result < usize > {
596- static IS_NONBLOCKING_READ_UNSUPPORTED : AtomicBool = AtomicBool :: new ( false ) ;
597-
598- if IS_NONBLOCKING_READ_UNSUPPORTED . load ( Ordering :: Relaxed ) {
599- return Err ( io:: ErrorKind :: Unsupported . into ( ) ) ;
600- }
601-
602- match cvt_ssize ( unsafe {
603- libc:: preadv2 (
604- fd,
605- & libc:: iovec {
606- iov_base : buf. as_ptr ( ) as * mut _ ,
607- iov_len : buf. len ( ) ,
608- } ,
609- 1 ,
610- -1 ,
611- libc:: RWF_NOWAIT ,
612- )
613- } ) {
614- Ok ( cnt) => Ok ( cnt. try_into ( ) . unwrap ( ) ) ,
615- Err ( err) if err. raw_os_error ( ) == Some ( libc:: EOPNOTSUPP ) => {
616- IS_NONBLOCKING_READ_UNSUPPORTED . store ( true , Ordering :: Relaxed ) ;
617- Err ( io:: ErrorKind :: Unsupported . into ( ) )
618- }
619- Err ( err) if err. kind ( ) == io:: ErrorKind :: Unsupported => {
620- IS_NONBLOCKING_READ_UNSUPPORTED . store ( true , Ordering :: Relaxed ) ;
621- Err ( err)
622- }
623- Err ( err) => Err ( err) ,
624- }
625- }
626-
627556#[ cfg( test) ]
628557mod test {
629558 use super :: Client as ClientImp ;
0 commit comments