/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/***********************************************************************
**
** Name: thrpool.c
**
** Description: Test threadpool functionality.
**
** Modification History:
*/
#include "primpl.h"
#include "plgetopt.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifdef XP_UNIX
#endif
#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS)
#include <pthread.h>
#endif
/* for getcwd */
#include <unistd.h>
#include <direct.h>
#endif
#ifdef WIN32
#include <process.h>
#endif
static int _debug_on = 0;
static void serve_client_write(void *arg);
#ifdef XP_MAC
#include "prlog.h"
#include "prsem.h"
{
return 0;
}
extern void SetupMacPrintfLog(char *logFile);
#else
#endif
#ifdef XP_PC
#define mode_t int
#endif
static void TCP_Server_Accept(void *arg);
int failed_already=0;
typedef struct buffer {
} buffer;
typedef struct Server_Param {
} Server_Param;
typedef struct Serve_Client_Param {
typedef struct Session {
} Session;
static void
{
int rem;
int bytes;
int offset;
char *buf;
if (bytes < 0) {
return;
}
PR_FALSE);
return;
}
PR_FALSE);
return;
}
static void
{
int bytes;
char *buf;
if (bytes < 0) {
return;
}
sp->bytes_read = 0;
PR_FALSE);
return;
}
}
--(*sp->job_counterp);
return;
}
/*
* Serve_Client
* Thread, started by the server, for serving a client connection.
* Reads data from socket and writes it back, unmodified, and
* closes the socket
*/
static void PR_CALLBACK
{
return;
}
sp->bytes_read = 0;
PR_FALSE);
}
static void
{
}
static int job_counter = 0;
/*
* TCP Server
* Server binds an address to a socket, starts a client process and
* listens for incoming connections.
* Each client connects to the server and sends a chunk of data
* Starts a Serve_Client job for each incoming connection, to read
* the data from the client and send it back to the client, unmodified.
* Each client checks that data received from server is same as the
* data it sent to the server.
* Finally, the threadpool is shutdown
*/
static void PR_CALLBACK
{
int i;
/*
* Create a tcp socket
*/
return;
}
/*
* try a few times to bind server's address, if addresses are in
* use
*/
i = 0;
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
if (i++ < SERVER_MAX_BIND_COUNT)
continue;
}
perror("PR_Bind");
return;
}
return;
}
return;
}
DPRINTF((
"TCP_Server: PR_BIND netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
return;
}
sp->conn_counter = 0;
/* create and cancel an io job */
PR_FALSE);
/*
* create the client process
*/
{
int index = 0;
#ifdef XP_PC
#endif
if (_debug_on)
{
} else {
}
"thrpool_server: ERROR - PR_CreateProcessDetached failed\n");
return;
}
}
sc_mon = PR_NewMonitor();
return;
}
sp->conn_counter = 0;
/* create and cancel a timer job */
DPRINTF(("TCP_Server: Accepting connections \n"));
PR_FALSE);
return;
}
static void
{
PR_INTERVAL_NO_TIMEOUT)) == NULL) {
goto exit;
}
goto exit;
}
/*
* Start a Serve_Client job for each incoming connection
*/
(*sp->job_counterp)++;
PR_FALSE);
/*
* single-threaded update; no lock needed
*/
sp->conn_counter++;
if (sp->conn_counter <
PR_FALSE);
return;
}
exit:
/* Wait for server jobs to finish */
while (0 != *sp->job_counterp) {
DPRINTF(("TCP_Server: conn_counter = %d\n",
*sp->job_counterp));
}
}
}
/************************************************************************/
int
{
/*
* -d debug mode
*/
program_name = argv[0];
{
if (PL_OPT_BAD == os) continue;
{
case 'd': /* debug mode */
_debug_on = 1;
break;
default:
break;
}
}
#ifdef XP_MAC
SetupMacPrintfLog("socket.log");
#endif
printf("PR_CreateThreadPool failed\n");
goto done;
}
done:
PR_Cleanup();
if (failed_already) return 1;
else return 0;
}