header juggling & print thread id
roberts [Wed, 28 Jul 1999 00:34:49 +0000 (00:34 +0000)]
examples/threaded.c

index 8618187..8b817b5 100755 (executable)
@@ -1,22 +1,25 @@
-/* 
+/*
  * threaded.c -- A simple multi-threaded FastCGI application.
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: threaded.c,v 1.1 1999/07/26 04:28:07 roberts Exp $";
+static const char rcsid[] = "$Id: threaded.c,v 1.2 1999/07/28 00:34:49 roberts Exp $";
 #endif /* not lint */
 
-#if defined HAVE_UNISTD_H || defined __linux__
+#include "fcgi_config.h"
+
+#include <pthread.h>
+
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
-#include "fcgiapp.h"
-
 #ifdef _WIN32
 #include <process.h>
 #endif
 
-#include <pthread.h>
+#include "fcgiapp.h"
+
 
 #define THREAD_COUNT 20
 
@@ -24,25 +27,26 @@ int count[THREAD_COUNT];
 
 static void *doit(void *a)
 {
-    int k = (int)a;
+    int i, k = (int)a;
     FCGX_Request request;
     FCGX_Stream *in, *out, *err;
     FCGX_ParamArray envp;
-    int i;
+    char *server_name;
 
     FCGX_InitRequest(&request);
 
     while (FCGX_Accept_r(&in, &out, &err, &envp, &request) >= 0)
     {
-        FCGX_FPrintF(out,
-           "Content-type: text/html\r\n"
-           "\r\n"
-           "<title>FastCGI Hello! (multi-threaded C, fcgiapp library)</title>"
-           "<h1>FastCGI Hello! (multi-threaded C, fcgiapp library)</h1>"
-           "Request counts for %d threads running on host <i>%s</i><P><CODE>",
-              THREAD_COUNT, FCGX_GetParam("SERVER_NAME", envp));
+        server_name = FCGX_GetParam("SERVER_NAME", envp);
 
-        count[k]++;
+        FCGX_FPrintF(out,
+            "Content-type: text/html\r\n"
+            "\r\n"
+            "<title>FastCGI Hello! (multi-threaded C, fcgiapp library)</title>"
+            "<h1>FastCGI Hello! (multi-threaded C, fcgiapp library)</h1>"
+            "Thread %d, Request %d<p>"
+            "Request counts for %d threads running on host <i>%s</i><p><code>",
+            k, ++count[k], THREAD_COUNT, server_name ? server_name : "?");
 
         for (i = 0; i < THREAD_COUNT; i++)
             FCGX_FPrintF(out, "%5d " , count[i]);
@@ -63,7 +67,7 @@ int main(void)
 
     for (i = 1; i < THREAD_COUNT; i++)
         pthread_create(&id[i], NULL, doit, (void*)i);
-   
+
     doit(0);
 
     exit(0);