Bug fixes and select on FIFOs in wcgi - doesn't really work!
[egate.git] / www / wcgi.c
index 60591ff..28f388e 100644 (file)
  * USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * $Log: wcgi.c,v $
- * Revision 1.3  1995/10/31 16:56:24  adam
+ * Revision 1.4  1995/11/02 16:35:37  adam
+ * Bug fixes and select on FIFOs in wcgi - doesn't really work!
+ *
+ * Revision 1.3  1995/10/31  16:56:24  adam
  * Record presentation.
  *
  * Revision 1.2  1995/10/23  16:55:36  adam
@@ -213,7 +216,7 @@ int main()
     }
     gw_log (GW_LOG_DEBUG, prog, "Reading response.");
 
-#if 1
+#if 0
     while ((data = read(linein, combuf, COMBUF)) > 0)
     {
         gw_log (GW_LOG_DEBUG, prog, "Got %d bytes", data);
@@ -224,27 +227,55 @@ int main()
         }
     }
 #else
+#  if 1
     fcntl (linein, F_SETFL, O_NONBLOCK);
+#  endif
     while (1)
     {
-        fd_set s_input, s_output;
+        fd_set s_input;
+        struct timeval t;
         int r;
     
+        t.tv_sec = 5;
+        t.tv_usec = 0;
        FD_ZERO(&s_input);
-       FD_ZERO(&s_output);
        FD_SET(linein, &s_input);
-#if 0
+#  if 0
        FD_SET(1, &s_output);
-#endif
-        r = select (linein + 1, &s_input, &s_output, NULL, 0);
-        if (r <= 0)
+#  endif
+        gw_log (GW_LOG_DEBUG, prog, "select");
+        r = select (linein + 1, &s_input, NULL, NULL, NULL);
+        if (r < 0)
         {
             gw_log (GW_LOG_ERRNO|GW_LOG_FATAL, prog, "select");
             exit(1);
         }
+        if (r == 0) 
+        {
+            gw_log (GW_LOG_DEBUG, prog, "poll");
+            if ((data = read (linein, combuf, COMBUF)) > 0)
+            {
+                gw_log (GW_LOG_DEBUG, prog, "Got %d bytes", data);
+                if (write(1, combuf, data) < data)
+                {
+                    gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, prog, "write");
+                    exit (1);
+                }
+            }
+            else if (data == -1)
+            {
+                gw_log (GW_LOG_DEBUG, prog, "No data");
+            }
+            else
+            {
+                gw_log (GW_LOG_DEBUG, prog, "No more");
+                break;
+            }
+            continue;
+        }
         if (FD_ISSET (linein, &s_input))
         {
-            data = read(linein, combuf, COMBUF);
+            data = read (linein, combuf, COMBUF);
             if (data == 0)
                 break;
             else if (data < 0)
@@ -259,7 +290,7 @@ int main()
                 exit (1);
             }
         }
-        if (FD_ISSET (1, &s_output))
+        if (FD_ISSET (1, &s_input))
         {
             gw_log (GW_LOG_DEBUG, prog, "stdout closed");
             break;