From: Brendan O'Dea Date: Fri, 22 Oct 2004 13:30:33 +0000 (+1000) Subject: ext/IO/IO.xs: fix blocking on sparc linux X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b2f3eeb7db34430d0f2a4bbc1b52e70a34987d0;p=p5sagit%2Fp5-mst-13.2.git ext/IO/IO.xs: fix blocking on sparc linux Message-ID: <20041022033033.GA12362@londo.c47.org> Date: Fri, 22 Oct 2004 13:30:33 +1000 p4raw-id: //depot/perl@23416 --- diff --git a/ext/IO/IO.xs b/ext/IO/IO.xs index 4f713a0..39e4486 100644 --- a/ext/IO/IO.xs +++ b/ext/IO/IO.xs @@ -73,53 +73,24 @@ io_blocking(pTHX_ InputStream f, int block) RETVAL = fcntl(PerlIO_fileno(f), F_GETFL, 0); if (RETVAL >= 0) { int mode = RETVAL; + int newmode = mode; #ifdef O_NONBLOCK /* POSIX style */ -#if defined(O_NDELAY) && O_NDELAY != O_NONBLOCK - /* Ooops has O_NDELAY too - make sure we don't - * get SysV behaviour by mistake. */ - /* E.g. In UNICOS and UNICOS/mk a F_GETFL returns an O_NDELAY +# ifndef O_NDELAY +# define O_NDELAY O_NONBLOCK +# endif + /* Note: UNICOS and UNICOS/mk a F_GETFL returns an O_NDELAY * after a successful F_SETFL of an O_NONBLOCK. */ RETVAL = RETVAL & (O_NONBLOCK | O_NDELAY) ? 0 : 1; - if (block >= 0) { - if ((mode & O_NDELAY) || ((block == 0) && !(mode & O_NONBLOCK))) { - int ret; - mode = (mode & ~O_NDELAY) | O_NONBLOCK; - ret = fcntl(PerlIO_fileno(f),F_SETFL,mode); - if(ret < 0) - RETVAL = ret; - } - else - if ((mode & O_NDELAY) || ((block > 0) && (mode & O_NONBLOCK))) { - int ret; - mode &= ~(O_NONBLOCK | O_NDELAY); - ret = fcntl(PerlIO_fileno(f),F_SETFL,mode); - if(ret < 0) - RETVAL = ret; - } + if (block == 0) { + newmode &= ~O_NDELAY; + newmode |= O_NONBLOCK; + } else if (block > 0) { + newmode &= ~(O_NDELAY|O_NONBLOCK); } #else - /* Standard POSIX */ - RETVAL = RETVAL & O_NONBLOCK ? 0 : 1; - - if ((block == 0) && !(mode & O_NONBLOCK)) { - int ret; - mode |= O_NONBLOCK; - ret = fcntl(PerlIO_fileno(f),F_SETFL,mode); - if(ret < 0) - RETVAL = ret; - } - else if ((block > 0) && (mode & O_NONBLOCK)) { - int ret; - mode &= ~O_NONBLOCK; - ret = fcntl(PerlIO_fileno(f),F_SETFL,mode); - if(ret < 0) - RETVAL = ret; - } -#endif -#else /* Not POSIX - better have O_NDELAY or we can't cope. * for BSD-ish machines this is an acceptable alternative * for SysV we can't tell "would block" from EOF but that is @@ -127,21 +98,18 @@ io_blocking(pTHX_ InputStream f, int block) */ RETVAL = RETVAL & O_NDELAY ? 0 : 1; - if ((block == 0) && !(mode & O_NDELAY)) { - int ret; - mode |= O_NDELAY; - ret = fcntl(PerlIO_fileno(f),F_SETFL,mode); - if(ret < 0) - RETVAL = ret; - } - else if ((block > 0) && (mode & O_NDELAY)) { + if (block == 0) { + newmode |= O_NDELAY; + } else if (block > 0) { + newmode &= ~O_NDELAY; + } +#endif + if (newmode != mode) { int ret; - mode &= ~O_NDELAY; - ret = fcntl(PerlIO_fileno(f),F_SETFL,mode); - if(ret < 0) + ret = fcntl(PerlIO_fileno(f),F_SETFL,newmode); + if (ret < 0) RETVAL = ret; - } -#endif + } } return RETVAL; #else