-/*
+/*
* 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
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]);
for (i = 1; i < THREAD_COUNT; i++)
pthread_create(&id[i], NULL, doit, (void*)i);
-
+
doit(0);
exit(0);