Index: /trunk/libc/tests/libc/smoketests/nonblock-1.c
===================================================================
--- /trunk/libc/tests/libc/smoketests/nonblock-1.c	(revision 3707)
+++ /trunk/libc/tests/libc/smoketests/nonblock-1.c	(revision 3708)
@@ -31,22 +31,43 @@
 #include <sys/socket.h>
 #include <sys/fcntl.h>
+#include <sys/filio.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <signal.h>
 
+static void sigAlarmHandler(int iSig)
+{
+    /* do nothing */
+}
 
 int main(int argc, char **argv)
 {
     char    abBuf[128];
+    int     pair[2];
+    int     fFlags;
+    int     fDontBlock;
+    int     rc;
     ssize_t cb;
-    int pair[2];
-    int rc;
-    int fFlags;
+
+    /* 
+     * Install a signal handler for alarms.
+     */
+    if (signal(SIGALRM, sigAlarmHandler) == SIG_ERR)
+    {
+        printf("nonblock-1: signal(SIGALRM,) failed, errno=%d: %s\n", errno, strerror(errno));
+        return 1;
+    }
+    if (siginterrupt(SIGALRM, 1) != 0)
+    {
+        printf("nonblock-1: siginterrupt(SIGALRM, 1) failed, errno=%d: %s\n", errno, strerror(errno));
+        return 1;
+    }
 
     /*
      * Create a socket pair.
      */
-    rc = socketpair(AF_LOCAL, SOCK_STREAM, 0, &pair[0]);
+    rc = socketpair(AF_UNIX, SOCK_STREAM, 0, &pair[0]);
     if (rc < 0)
     {
@@ -54,4 +75,10 @@
         return 1;
     }
+
+    /* 
+     *
+     * The fcntl way.
+     *
+     */
 
     /*
@@ -78,11 +105,88 @@
      */
     /** @todo this should be done with a timer pending or a parent watching. */
+    alarm(5);
     cb = read(pair[0], abBuf, sizeof(abBuf));
     if (cb != -1 || errno != EWOULDBLOCK)
     {
         printf("nonblock-1: read didn't return -1 and errno=%d! cb=%zd errno=%d: %s\n", 
-               cb, EWOULDBLOCK, errno, strerror(errno));
+               EWOULDBLOCK, cb, errno, strerror(errno));
         return 1;
     }
+    alarm(0);
+    printf("nonblock-1: test #1 - non-blocking test - succeeded\n");
+
+
+    /*
+     * Change back to blocking mode and try read from the pipe now.
+     */
+    rc = fcntl(pair[0], F_SETFL, fFlags & ~O_NONBLOCK);
+    if (rc < 0)
+    {
+        printf("nonblock-1: F_SETFL(%#x) failed, rc=%d errno=%d: %s\n", fFlags & ~O_NONBLOCK, rc, errno, strerror(errno));
+        return 1;
+    }
+    alarm(5);
+    cb = read(pair[0], abBuf, sizeof(abBuf));
+    if (cb != -1 || errno != EINTR)
+    {
+        alarm(0);
+        printf("nonblock-1: read didn't return -1 and errno=%d! cb=%zd errno=%d: %s\n", 
+               EINTR, cb, errno, strerror(errno));
+        return 1;
+    }
+    alarm(0);
+    printf("nonblock-1: test #2 - blocking test - succeeded\n");
+
+
+    /* 
+     *
+     * Try the IOCTL.
+     *
+     */
+    
+    /*
+     * Nonblocking call.
+     */
+    fDontBlock = 1;
+    rc = ioctl(pair[0], FIONBIO, (char *)&fDontBlock);
+    if (rc < 0)
+    {
+        printf("nonblock-1: FIONBIO(1) failed, rc=%d errno=%d: %s\n", rc, errno, strerror(errno));
+        return 1;
+    }
+    alarm(5);
+    cb = read(pair[0], abBuf, sizeof(abBuf));
+    if (cb != -1 || errno != EWOULDBLOCK)
+    {
+        printf("nonblock-1: read didn't return -1 and errno=%d! cb=%zd errno=%d: %s\n", 
+               EWOULDBLOCK, cb, errno, strerror(errno));
+        return 1;
+    }
+    alarm(0);
+    printf("nonblock-1: test #3 - non-blocking test - succeeded\n");
+
+
+    /*
+     * Change back to blocking mode and try read from the pipe now.
+     */
+    fDontBlock = 0;
+    rc = ioctl(pair[0], FIONBIO, (char *)&fDontBlock);
+    if (rc < 0)
+    {
+        printf("nonblock-1: FIONBIO(0) failed, rc=%d errno=%d: %s\n", rc, errno, strerror(errno));
+        return 1;
+    }
+    alarm(5);
+    cb = read(pair[0], abBuf, sizeof(abBuf));
+    if (cb != -1 || errno != EINTR)
+    {
+        alarm(0);
+        printf("nonblock-1: read didn't return -1 and errno=%d! cb=%zd errno=%d: %s\n", 
+               EINTR, cb, errno, strerror(errno));
+        return 1;
+    }
+    alarm(0);
+    printf("nonblock-1: test #4 - blocking test - succeeded\n");
+    
 
     printf("nonblock-1: success\n");
