diff options
author | wtc%netscape.com <devnull@localhost> | 1999-02-24 19:53:48 +0000 |
---|---|---|
committer | wtc%netscape.com <devnull@localhost> | 1999-02-24 19:53:48 +0000 |
commit | 1b5f294996dcf23f585add370ffa0db475c9da66 (patch) | |
tree | 3d2d9d9a8bbc91f40ce1e798cda95636369cc9ac | |
parent | fa283bebd9045ac56e6a878912a7b797f5a96518 (diff) | |
download | nspr-hg-1b5f294996dcf23f585add370ffa0db475c9da66.tar.gz |
Bugzilla bug #3233: create the pipe in nonblocking mode and have
reads and writes check for the possible EAGAIN/EWOULDBLOCK error.
-rw-r--r-- | lib/ds/plevent.c | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/lib/ds/plevent.c b/lib/ds/plevent.c index 938c9073..b221a88a 100644 --- a/lib/ds/plevent.c +++ b/lib/ds/plevent.c @@ -35,6 +35,12 @@ typedef MPARAM WPARAM,LPARAM; #endif /* !XP_OS2 */ #endif /* !Win32 */ +#if defined(XP_UNIX) +/* for fcntl */ +#include <sys/types.h> +#include <fcntl.h> +#endif + #if defined(XP_MAC) #include <AppleEvents.h> #include "pprthred.h" @@ -581,11 +587,41 @@ _pl_SetupNativeNotifier(PLEventQueue* self) #pragma unused (self) #endif - PRInt32 err = 0; #if defined(XP_UNIX) + int err; + int flags; + err = pipe(self->eventPipe); + if (err != 0) { + return PR_FAILURE; + } + + /* make the pipe nonblocking */ + flags = fcntl(self->eventPipe[0], F_GETFL, 0); + if (flags == -1) { + goto failed; + } + err = fcntl(self->eventPipe[0], F_SETFL, flags | O_NONBLOCK); + if (err == -1) { + goto failed; + } + flags = fcntl(self->eventPipe[1], F_GETFL, 0); + if (flags == -1) { + goto failed; + } + err = fcntl(self->eventPipe[1], F_SETFL, flags | O_NONBLOCK); + if (err == -1) { + goto failed; + } + return PR_SUCCESS; + +failed: + close(self->eventPipe[0]); + close(self->eventPipe[1]); + return PR_FAILURE; +#else + return PR_SUCCESS; #endif - return err == 0 ? PR_SUCCESS : PR_FAILURE; } static void @@ -642,7 +678,8 @@ _pl_NativeNotify(PLEventQueue* self) count = write(self->eventPipe[1], buf, 1); self->notifyCount++; - return (count == 1) ? PR_SUCCESS : PR_FAILURE; + return (count == 1 || (count == -1 && (errno == EAGAIN + || errno == EWOULDBLOCK))) ? PR_SUCCESS : PR_FAILURE; }/* --- end _pl_NativeNotify() --- */ #endif /* XP_UNIX */ @@ -675,7 +712,8 @@ _pl_AcknowledgeNativeNotify(PLEventQueue* self) /* consume the byte NativeNotify put in our pipe: */ count = read(self->eventPipe[0], &c, 1); self->notifyCount--; - return ((count == 1 && c == NOTIFY_TOKEN) || count == 0) + return ((count == 1 && c == NOTIFY_TOKEN) || (count == -1 + && (errno == EAGAIN || errno == EWOULDBLOCK))) ? PR_SUCCESS : PR_FAILURE; #else |