summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan O'Dea <bod@debian.org>2004-10-22 23:30:33 +1000
committerNicholas Clark <nick@ccl4.org>2004-10-28 09:26:16 +0000
commitc44fb373b9cba2b968f418b3056b26bd823a77b2 (patch)
tree0465d766c7bbd7d707a058462fa6dceacc3ad70f
parentaef8ec01d60ce69b13358738019011b881f47e61 (diff)
downloadperl-c44fb373b9cba2b968f418b3056b26bd823a77b2.tar.gz
Integrate:
[ 23416] Subject: [PATCH] ext/IO/IO.xs: fix blocking on sparc linux Message-ID: <20041022033033.GA12362@londo.c47.org> p4raw-link: @23416 on //depot/perl: 3b2f3eeb7db34430d0f2a4bbc1b52e70a34987d0 p4raw-id: //depot/maint-5.8/perl@23428 p4raw-integrated: from //depot/perl@23427 'copy in' ext/IO/IO.xs (@22091..)
-rw-r--r--ext/IO/IO.xs72
1 files changed, 20 insertions, 52 deletions
diff --git a/ext/IO/IO.xs b/ext/IO/IO.xs
index 4f713a0917..39e4486f99 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