extern pthread_key_t MyConKey;
-
+char *server_cookie = NULL;
char *defaulthost = DEFAULT_HOST;
retval = client_read(sock, &buf[i], 1);
/*
- * Strip any trailing not-printable characters.
+ * Strip any trailing non-printable characters.
*/
buf[i] = 0;
while ((strlen(buf) > 0) && (!isprint(buf[strlen(buf) - 1]))) {
char tracefile[PATH_MAX];
/* Parse command line */
- while ((a = getopt(argc, argv, "hp:t:")) != EOF)
+ while ((a = getopt(argc, argv, "hp:t:c")) != EOF)
switch (a) {
case 'p':
port = atoi(optarg);
freopen(tracefile, "w", stderr);
freopen(tracefile, "r", stdin);
break;
+ case 'c':
+ server_cookie = malloc(SIZ);
+ if (server_cookie != NULL) {
+ strcpy(server_cookie, "Set-cookie: wcserver=");
+ if (gethostname(
+ &server_cookie[strlen(server_cookie)],
+ 200) != 0) {
+ fprintf(stderr, "gethostname: %s\n",
+ strerror(errno));
+ free(server_cookie);
+ }
+ }
+ break;
default:
fprintf(stderr, "usage: webserver [-p localport] "
- "[-t tracefile] "
+ "[-t tracefile] [-c] "
"[remotehost [remoteport]]\n");
return 1;
}
}
/* Tell 'em who's in da house */
fprintf(stderr, SERVER "\n"
- "Copyright (C) 1996-1999. All rights reserved.\n\n");
+ "Copyright (C) 1996-2001\n"
+ "This software is distributed under the terms of the GNU\n"
+ "General Public License. All other rights reserved.\n\n");
if (chdir(WEBCITDIR) != 0)
perror("chdir");
/* Start a few initial worker threads */
- for (i=0; i<(INITIAL_WORKER_THREADS-1); ++i) {
+ for (i=0; i<(INITIAL_WORKER_THREADS); ++i) {
spawn_another_worker_thread();
}
-
- /* now the original thread becomes an ordinary worker thread */
- worker_entry();
+ /* now the original thread can go away. */
pthread_exit(NULL);
+ return 0;
}
i = 1;
setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR,
&i, sizeof(i));
+
+ /* Perform an HTTP transaction... */
context_loop(ssock);
+
+ /* ...and close the socket. */
+ lingering_close(ssock);
}
} while (!time_to_die);