summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/tests/cltsrv.c
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
commitf7d30133221896638f7bf4f66c504255c4b14f48 (patch)
tree5f3e07a049f388a3a309a615b8884318f6668a98 /nsprpub/pr/tests/cltsrv.c
parent26b297510a11758727438df4669357a2a2bc42ce (diff)
downloadUXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.gz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.lz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.xz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.zip
Issue #1338 - Part 1: Update NSPR to 4.24
Diffstat (limited to 'nsprpub/pr/tests/cltsrv.c')
-rw-r--r--nsprpub/pr/tests/cltsrv.c373
1 files changed, 218 insertions, 155 deletions
diff --git a/nsprpub/pr/tests/cltsrv.c b/nsprpub/pr/tests/cltsrv.c
index 1941687eb..caf1ad4d6 100644
--- a/nsprpub/pr/tests/cltsrv.c
+++ b/nsprpub/pr/tests/cltsrv.c
@@ -23,7 +23,7 @@
* The debug mode will print all of the printfs associated with this test.
* The regress mode will be the default mode. Since the regress tool limits
* the output to a one line status:PASS or FAIL,all of the printf statements
- * have been handled with an if (debug_mode) statement.
+ * have been handled with an if (debug_mode) statement.
*/
#include "prclist.h"
@@ -182,7 +182,7 @@ static void _MY_Assert(const char *s, const char *file, PRIntn ln)
static PRBool Aborted(PRStatus rv)
{
return ((PR_FAILURE == rv) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) ?
- PR_TRUE : PR_FALSE;
+ PR_TRUE : PR_FALSE;
}
static void TimeOfDayMessage(const char *msg, PRThread* me)
@@ -211,8 +211,9 @@ static void PR_CALLBACK Client(void *arg)
PRIntervalTime timeout = PR_MillisecondsToInterval(DEFAULT_CLIENT_TIMEOUT);
- for (index = 0; index < sizeof(buffer); ++index)
+ for (index = 0; index < sizeof(buffer); ++index) {
buffer[index] = (char)index;
+ }
client->started = PR_IntervalNow();
@@ -228,8 +229,8 @@ static void PR_CALLBACK Client(void *arg)
PRInt32 bytes, descbytes, filebytes, netbytes;
(void)PR_NetAddrToString(&client->serverAddress, buffer, sizeof(buffer));
- TEST_LOG(cltsrv_log_file, TEST_LOG_INFO,
- ("\tClient(0x%p): connecting to server at %s\n", me, buffer));
+ TEST_LOG(cltsrv_log_file, TEST_LOG_INFO,
+ ("\tClient(0x%p): connecting to server at %s\n", me, buffer));
fd = PR_Socket(domain, SOCK_STREAM, protocol);
TEST_ASSERT(NULL != fd);
@@ -239,7 +240,7 @@ static void PR_CALLBACK Client(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): conection failed (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
@@ -252,10 +253,12 @@ static void PR_CALLBACK Client(void *arg)
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): sending descriptor for %u bytes\n", me, descbytes));
bytes = PR_Send(
- fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
+ fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
if (sizeof(CSDescriptor_t) != bytes)
{
- if (Aborted(PR_FAILURE)) goto aborted;
+ if (Aborted(PR_FAILURE)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -270,15 +273,18 @@ static void PR_CALLBACK Client(void *arg)
while (netbytes < descbytes)
{
filebytes = sizeof(buffer);
- if ((descbytes - netbytes) < filebytes)
+ if ((descbytes - netbytes) < filebytes) {
filebytes = descbytes - netbytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): sending %d bytes\n", me, filebytes));
bytes = PR_Send(fd, buffer, filebytes, SEND_FLAGS, timeout);
if (filebytes != bytes)
{
- if (Aborted(PR_FAILURE)) goto aborted;
+ if (Aborted(PR_FAILURE)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -294,8 +300,9 @@ static void PR_CALLBACK Client(void *arg)
while (filebytes < descbytes)
{
netbytes = sizeof(buffer);
- if ((descbytes - filebytes) < netbytes)
+ if ((descbytes - filebytes) < netbytes) {
netbytes = descbytes - filebytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): receiving %d bytes\n", me, netbytes));
@@ -313,26 +320,28 @@ static void PR_CALLBACK Client(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): receive data timeout\n", me));
- else
+ else
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): receive error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto retry;
- }
+ }
if (0 == bytes)
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tClient(0x%p): unexpected end of stream\n",
- PR_GetCurrentThread()));
+ PR_GetCurrentThread()));
break;
}
filebytes += bytes;
}
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
retry:
(void)PR_Close(fd); fd = NULL;
@@ -345,14 +354,18 @@ retry:
client->bytesTransferred += 2 * descbytes;
rv = PR_WaitCondVar(client->stateChange, rand() % clipping);
PR_Unlock(client->ml);
- if (Aborted(rv)) break;
+ if (Aborted(rv)) {
+ break;
+ }
}
aborted:
client->stopped = PR_IntervalNow();
PR_ClearInterrupt();
- if (NULL != fd) rv = PR_Close(fd);
+ if (NULL != fd) {
+ rv = PR_Close(fd);
+ }
PR_Lock(client->ml);
client->state = cs_exit;
@@ -362,7 +375,7 @@ aborted:
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("\tClient(0x%p): stopped after %u operations and %u bytes\n",
- PR_GetCurrentThread(), client->operations, client->bytesTransferred));
+ PR_GetCurrentThread(), client->operations, client->bytesTransferred));
} /* Client */
@@ -380,11 +393,13 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): receiving desciptor\n", me));
bytes = PR_Recv(
- fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
+ fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
if (-1 == bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto exit;
+ if (Aborted(rv)) {
+ goto exit;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -405,16 +420,18 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_ASSERT(sizeof(*descriptor) == bytes);
TEST_LOG(
- cltsrv_log_file, TEST_LOG_VERBOSE,
+ cltsrv_log_file, TEST_LOG_VERBOSE,
("\t\tProcessRequest(0x%p): read descriptor {%d, %s}\n",
- me, descbytes, descriptor->filename));
+ me, descbytes, descriptor->filename));
file = PR_Open(
- descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
+ descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
if (NULL == file)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -429,8 +446,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
while (filebytes < descbytes)
{
netbytes = sizeof(buffer);
- if ((descbytes - filebytes) < netbytes)
+ if ((descbytes - filebytes) < netbytes) {
netbytes = descbytes - filebytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): receive %d bytes\n", me, netbytes));
@@ -438,7 +456,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (-1 == bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -454,7 +474,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_WARNING,
("\t\tProcessRequest(0x%p): unexpected error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
if(0 == bytes)
@@ -476,7 +496,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (netbytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -494,7 +516,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
PR_Unlock(server->ml);
rv = PR_Close(file);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
file = NULL;
@@ -505,19 +529,21 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (NULL == file)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): open file timeout\n",
- PR_GetCurrentThread()));
+ PR_GetCurrentThread()));
goto aborted;
}
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): other file open error (%u, %u)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
TEST_ASSERT(NULL != file);
@@ -526,8 +552,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
while (netbytes < descbytes)
{
filebytes = sizeof(buffer);
- if ((descbytes - netbytes) < filebytes)
+ if ((descbytes - netbytes) < filebytes) {
filebytes = descbytes - netbytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): read %d bytes from file\n", me, filebytes));
@@ -535,7 +562,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (filebytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
@@ -544,7 +573,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): other file error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
TEST_ASSERT(bytes > 0);
@@ -557,7 +586,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (filebytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -567,24 +598,30 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
}
break;
}
- TEST_ASSERT(bytes > 0);
+ TEST_ASSERT(bytes > 0);
}
-
+
PR_Lock(server->ml);
server->bytesTransferred += filebytes;
PR_Unlock(server->ml);
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
rv = PR_Close(file);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
file = NULL;
aborted:
PR_ClearInterrupt();
- if (NULL != file) PR_Close(file);
+ if (NULL != file) {
+ PR_Close(file);
+ }
drv = PR_Delete(descriptor->filename);
TEST_ASSERT(PR_SUCCESS == drv);
exit:
@@ -606,18 +643,18 @@ static PRStatus CreateWorker(CSServer_t *server, CSPool_t *pool)
worker->server = server;
PR_INIT_CLIST(&worker->element);
worker->thread = PR_CreateThread(
- PR_USER_THREAD, Worker, worker,
- DEFAULT_SERVER_PRIORITY, thread_scope,
- PR_UNJOINABLE_THREAD, 0);
+ PR_USER_THREAD, Worker, worker,
+ DEFAULT_SERVER_PRIORITY, thread_scope,
+ PR_UNJOINABLE_THREAD, 0);
if (NULL == worker->thread)
{
PR_DELETE(worker);
return PR_FAILURE;
}
- TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
- ("\tCreateWorker(0x%p): create new worker (0x%p)\n",
- PR_GetCurrentThread(), worker->thread));
+ TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
+ ("\tCreateWorker(0x%p): create new worker (0x%p)\n",
+ PR_GetCurrentThread(), worker->thread));
return PR_SUCCESS;
} /* CreateWorker */
@@ -647,17 +684,17 @@ static void PR_CALLBACK Worker(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\t\tWorker(0x%p): waiting for accept slot[%d]\n",
- me, pool->accepting));
+ me, pool->accepting));
rv = PR_WaitCondVar(pool->acceptComplete, PR_INTERVAL_NO_TIMEOUT);
if (Aborted(rv) || (cs_run != server->state))
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("\tWorker(0x%p): has been %s\n",
- me, (Aborted(rv) ? "interrupted" : "stopped")));
+ me, (Aborted(rv) ? "interrupted" : "stopped")));
goto exit;
}
- }
+ }
pool->accepting += 1; /* how many are really in accept */
PR_Unlock(server->ml);
@@ -666,7 +703,7 @@ static void PR_CALLBACK Worker(void *arg)
("\t\tWorker(0x%p): calling accept\n", me));
fd = PR_Accept(server->listener, &from, PR_INTERVAL_NO_TIMEOUT);
- PR_Lock(server->ml);
+ PR_Lock(server->ml);
pool->accepting -= 1;
PR_NotifyCondVar(pool->acceptComplete);
@@ -692,13 +729,15 @@ static void PR_CALLBACK Worker(void *arg)
*/
PRBool another =
((pool->workers < server->workers.minimum) ||
- ((0 == pool->accepting)
- && (pool->workers < server->workers.maximum))) ?
- PR_TRUE : PR_FALSE;
+ ((0 == pool->accepting)
+ && (pool->workers < server->workers.maximum))) ?
+ PR_TRUE : PR_FALSE;
pool->active += 1;
PR_Unlock(server->ml);
- if (another) (void)CreateWorker(server, pool);
+ if (another) {
+ (void)CreateWorker(server, pool);
+ }
rv = ProcessRequest(fd, server);
if (PR_SUCCESS != rv)
@@ -713,7 +752,7 @@ static void PR_CALLBACK Worker(void *arg)
}
exit:
- PR_ClearInterrupt();
+ PR_ClearInterrupt();
PR_Unlock(server->ml);
if (NULL != fd)
@@ -752,11 +791,12 @@ static void PR_CALLBACK Server(void *arg)
TEST_ASSERT(PR_SUCCESS == rv);
memset(&serverAddress, 0, sizeof(serverAddress));
- if (PR_AF_INET6 != domain)
- rv = PR_InitializeNetAddr(PR_IpAddrAny, DEFAULT_PORT, &serverAddress);
- else
- rv = PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET6, DEFAULT_PORT,
- &serverAddress);
+ if (PR_AF_INET6 != domain) {
+ rv = PR_InitializeNetAddr(PR_IpAddrAny, DEFAULT_PORT, &serverAddress);
+ }
+ else
+ rv = PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET6, DEFAULT_PORT,
+ &serverAddress);
rv = PR_Bind(server->listener, &serverAddress);
TEST_ASSERT(PR_SUCCESS == rv);
@@ -827,7 +867,7 @@ static void PR_CALLBACK Server(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("\tServer(0x%p): waiting for %u workers to exit\n",
- me, server->pool.workers));
+ me, server->pool.workers));
(void)PR_WaitCondVar(server->pool.exiting, PR_INTERVAL_NO_TIMEOUT);
}
@@ -838,9 +878,11 @@ static void PR_CALLBACK Server(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("\tServer(0x%p): stopped after %u operations and %u bytes\n",
- me, server->operations, server->bytesTransferred));
+ me, server->operations, server->bytesTransferred));
- if (NULL != server->listener) PR_Close(server->listener);
+ if (NULL != server->listener) {
+ PR_Close(server->listener);
+ }
server->stopped = PR_IntervalNow();
} /* Server */
@@ -848,10 +890,12 @@ static void PR_CALLBACK Server(void *arg)
static void WaitForCompletion(PRIntn execution)
{
while (execution > 0)
- {
+ {
PRIntn dally = (execution > 30) ? 30 : execution;
PR_Sleep(PR_SecondsToInterval(dally));
- if (pthread_stats) PT_FPrintStats(debug_out, "\nPThread Statistics\n");
+ if (pthread_stats) {
+ PT_FPrintStats(debug_out, "\nPThread Statistics\n");
+ }
execution -= dally;
}
} /* WaitForCompletion */
@@ -922,70 +966,86 @@ int main(int argc, char** argv)
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'G': /* use global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'X': /* use XTP as transport */
- protocol = 36;
- break;
- case '6': /* Use IPv6 */
- domain = PR_AF_INET6;
- break;
- case 'a': /* the value for accepting */
- accepting = atoi(opt->value);
- break;
- case 'b': /* the value for backlock */
- backlog = atoi(opt->value);
- break;
- case 'c': /* number of client threads */
- clients = atoi(opt->value);
- break;
- case 'f': /* low water fd cache */
- low = atoi(opt->value);
- break;
- case 'F': /* low water fd cache */
- high = atoi(opt->value);
- break;
- case 'w': /* minimum server worker threads */
- workersMin = atoi(opt->value);
- break;
- case 'W': /* maximum server worker threads */
- workersMax = atoi(opt->value);
- break;
- case 'e': /* program execution time in seconds */
- execution = atoi(opt->value);
- break;
- case 's': /* server's address */
- serverName = opt->value;
- break;
- case 'v': /* verbosity */
- verbosity = IncrementVerbosity();
- break;
- case 'd': /* debug mode */
- debug_mode = PR_TRUE;
- break;
- case 'p': /* pthread mode */
- pthread_stats = PR_TRUE;
- break;
- case 'h':
- default:
- Help();
- return 2;
+ case 'G': /* use global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'X': /* use XTP as transport */
+ protocol = 36;
+ break;
+ case '6': /* Use IPv6 */
+ domain = PR_AF_INET6;
+ break;
+ case 'a': /* the value for accepting */
+ accepting = atoi(opt->value);
+ break;
+ case 'b': /* the value for backlock */
+ backlog = atoi(opt->value);
+ break;
+ case 'c': /* number of client threads */
+ clients = atoi(opt->value);
+ break;
+ case 'f': /* low water fd cache */
+ low = atoi(opt->value);
+ break;
+ case 'F': /* low water fd cache */
+ high = atoi(opt->value);
+ break;
+ case 'w': /* minimum server worker threads */
+ workersMin = atoi(opt->value);
+ break;
+ case 'W': /* maximum server worker threads */
+ workersMax = atoi(opt->value);
+ break;
+ case 'e': /* program execution time in seconds */
+ execution = atoi(opt->value);
+ break;
+ case 's': /* server's address */
+ serverName = opt->value;
+ break;
+ case 'v': /* verbosity */
+ verbosity = IncrementVerbosity();
+ break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'p': /* pthread mode */
+ pthread_stats = PR_TRUE;
+ break;
+ case 'h':
+ default:
+ Help();
+ return 2;
}
}
PL_DestroyOptState(opt);
- if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) serverIsLocal = PR_FALSE;
- if (0 == execution) execution = DEFAULT_EXECUTION_TIME;
- if (0 == workersMax) workersMax = DEFAULT_WORKERS_MAX;
- if (0 == workersMin) workersMin = DEFAULT_WORKERS_MIN;
- if (0 == accepting) accepting = ALLOWED_IN_ACCEPT;
- if (0 == backlog) backlog = DEFAULT_BACKLOG;
+ if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) {
+ serverIsLocal = PR_FALSE;
+ }
+ if (0 == execution) {
+ execution = DEFAULT_EXECUTION_TIME;
+ }
+ if (0 == workersMax) {
+ workersMax = DEFAULT_WORKERS_MAX;
+ }
+ if (0 == workersMin) {
+ workersMin = DEFAULT_WORKERS_MIN;
+ }
+ if (0 == accepting) {
+ accepting = ALLOWED_IN_ACCEPT;
+ }
+ if (0 == backlog) {
+ backlog = DEFAULT_BACKLOG;
+ }
- if (workersMin > accepting) accepting = workersMin;
+ if (workersMin > accepting) {
+ accepting = workersMin;
+ }
PR_STDIO_INIT();
TimeOfDayMessage("Client/Server started at", PR_GetCurrentThread());
@@ -1023,8 +1083,8 @@ int main(int argc, char** argv)
("main(0x%p): creating server thread\n", PR_GetCurrentThread()));
server->thread = PR_CreateThread(
- PR_USER_THREAD, Server, server, PR_PRIORITY_HIGH,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Server, server, PR_PRIORITY_HIGH,
+ thread_scope, PR_JOINABLE_THREAD, 0);
TEST_ASSERT(NULL != server->thread);
TEST_LOG(
@@ -1032,14 +1092,15 @@ int main(int argc, char** argv)
("main(0x%p): waiting for server init\n", PR_GetCurrentThread()));
PR_Lock(server->ml);
- while (server->state == cs_init)
+ while (server->state == cs_init) {
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(server->ml);
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("main(0x%p): server init complete (port #%d)\n",
- PR_GetCurrentThread(), server->port));
+ PR_GetCurrentThread(), server->port));
}
if (clients != 0)
@@ -1052,8 +1113,8 @@ int main(int argc, char** argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("main(0x%p): creating %d client threads\n",
- PR_GetCurrentThread(), clients));
-
+ PR_GetCurrentThread(), clients));
+
if (!serverIsLocal)
{
rv = PR_GetHostByName(serverName, buffer, BUFFER_SIZE, &host);
@@ -1070,13 +1131,13 @@ int main(int argc, char** argv)
client[index].ml = PR_NewLock();
if (serverIsLocal)
{
- if (PR_AF_INET6 != domain)
- (void)PR_InitializeNetAddr(
- PR_IpAddrLoopback, DEFAULT_PORT,
- &client[index].serverAddress);
- else
- rv = PR_SetNetAddr(PR_IpAddrLoopback, PR_AF_INET6,
- DEFAULT_PORT, &client[index].serverAddress);
+ if (PR_AF_INET6 != domain)
+ (void)PR_InitializeNetAddr(
+ PR_IpAddrLoopback, DEFAULT_PORT,
+ &client[index].serverAddress);
+ else
+ rv = PR_SetNetAddr(PR_IpAddrLoopback, PR_AF_INET6,
+ DEFAULT_PORT, &client[index].serverAddress);
}
else
{
@@ -1088,12 +1149,13 @@ int main(int argc, char** argv)
cltsrv_log_file, TEST_LOG_INFO,
("main(0x%p): creating client threads\n", PR_GetCurrentThread()));
client[index].thread = PR_CreateThread(
- PR_USER_THREAD, Client, &client[index], PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Client, &client[index], PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
TEST_ASSERT(NULL != client[index].thread);
PR_Lock(client[index].ml);
- while (cs_init == client[index].state)
+ while (cs_init == client[index].state) {
PR_WaitCondVar(client[index].stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(client[index].ml);
}
}
@@ -1102,7 +1164,7 @@ int main(int argc, char** argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("main(0x%p): waiting for execution interval (%d seconds)\n",
- PR_GetCurrentThread(), execution));
+ PR_GetCurrentThread(), execution));
WaitForCompletion(execution);
@@ -1112,9 +1174,9 @@ int main(int argc, char** argv)
{
for (index = 0; index < clients; ++index)
{
- TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
- ("main(0x%p): notifying client(0x%p) to stop\n",
- PR_GetCurrentThread(), client[index].thread));
+ TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
+ ("main(0x%p): notifying client(0x%p) to stop\n",
+ PR_GetCurrentThread(), client[index].thread));
PR_Lock(client[index].ml);
if (cs_run == client[index].state)
@@ -1127,12 +1189,12 @@ int main(int argc, char** argv)
}
PR_Unlock(client[index].ml);
- TEST_LOG(cltsrv_log_file, TEST_LOG_VERBOSE,
- ("main(0x%p): joining client(0x%p)\n",
- PR_GetCurrentThread(), client[index].thread));
+ TEST_LOG(cltsrv_log_file, TEST_LOG_VERBOSE,
+ ("main(0x%p): joining client(0x%p)\n",
+ PR_GetCurrentThread(), client[index].thread));
- joinStatus = PR_JoinThread(client[index].thread);
- TEST_ASSERT(PR_SUCCESS == joinStatus);
+ joinStatus = PR_JoinThread(client[index].thread);
+ TEST_ASSERT(PR_SUCCESS == joinStatus);
PR_DestroyCondVar(client[index].stateChange);
PR_DestroyLock(client[index].ml);
}
@@ -1143,21 +1205,22 @@ int main(int argc, char** argv)
{
/* All clients joined - retrieve the server */
TEST_LOG(
- cltsrv_log_file, TEST_LOG_NOTICE,
+ cltsrv_log_file, TEST_LOG_NOTICE,
("main(0x%p): notifying server(0x%p) to stop\n",
- PR_GetCurrentThread(), server->thread));
+ PR_GetCurrentThread(), server->thread));
PR_Lock(server->ml);
server->state = cs_stop;
PR_Interrupt(server->thread);
- while (cs_exit != server->state)
+ while (cs_exit != server->state) {
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(server->ml);
TEST_LOG(
- cltsrv_log_file, TEST_LOG_NOTICE,
+ cltsrv_log_file, TEST_LOG_NOTICE,
("main(0x%p): joining server(0x%p)\n",
- PR_GetCurrentThread(), server->thread));
+ PR_GetCurrentThread(), server->thread));
joinStatus = PR_JoinThread(server->thread);
TEST_ASSERT(PR_SUCCESS == joinStatus);
@@ -1169,7 +1232,7 @@ int main(int argc, char** argv)
}
TEST_LOG(
- cltsrv_log_file, TEST_LOG_ALWAYS,
+ cltsrv_log_file, TEST_LOG_ALWAYS,
("main(0x%p): test complete\n", PR_GetCurrentThread()));
PT_FPrintStats(debug_out, "\nPThread Statistics\n");