nsprpub/pr/tests/servr_uu.c

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /***********************************************************************
michael@0 7 **
michael@0 8 ** This server simulates a server running in loopback mode.
michael@0 9 **
michael@0 10 ** The idea is that a single server is created. The server initially creates
michael@0 11 ** a number of worker threads. Then, with the server running, a number of
michael@0 12 ** clients are created which start requesting service from the server.
michael@0 13 **
michael@0 14 **
michael@0 15 ** Modification History:
michael@0 16 ** 19-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
michael@0 17 ** The debug mode will print all of the printfs associated with this test.
michael@0 18 ** The regress mode will be the default mode. Since the regress tool limits
michael@0 19 ** the output to a one line status:PASS or FAIL,all of the printf statements
michael@0 20 ** have been handled with an if (debug_mode) statement.
michael@0 21 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
michael@0 22 ** recognize the return code from tha main program.
michael@0 23 ***********************************************************************/
michael@0 24
michael@0 25 /***********************************************************************
michael@0 26 ** Includes
michael@0 27 ***********************************************************************/
michael@0 28 /* Used to get the command line option */
michael@0 29 #include "plgetopt.h"
michael@0 30
michael@0 31 #include "nspr.h"
michael@0 32 #include "pprthred.h"
michael@0 33
michael@0 34 #include <string.h>
michael@0 35
michael@0 36 #define PORT 15004
michael@0 37 #define THREAD_STACKSIZE 0
michael@0 38
michael@0 39 static int _iterations = 1000;
michael@0 40 static int _clients = 1;
michael@0 41 static int _client_data = 250;
michael@0 42 static int _server_data = (8*1024);
michael@0 43
michael@0 44 static PRThreadScope ServerScope, ClientScope;
michael@0 45
michael@0 46 #define SERVER "Server"
michael@0 47 #define MAIN "Main"
michael@0 48
michael@0 49 #define SERVER_STATE_STARTUP 0
michael@0 50 #define SERVER_STATE_READY 1
michael@0 51 #define SERVER_STATE_DYING 2
michael@0 52 #define SERVER_STATE_DEAD 4
michael@0 53 int ServerState;
michael@0 54 PRLock *ServerStateCVLock;
michael@0 55 PRCondVar *ServerStateCV;
michael@0 56
michael@0 57 #ifdef DEBUGPRINTS
michael@0 58 #define DPRINTF printf
michael@0 59 #else
michael@0 60 #define DPRINTF
michael@0 61 #endif
michael@0 62
michael@0 63 PRIntn failed_already=0;
michael@0 64 PRIntn debug_mode;
michael@0 65
michael@0 66 static void do_work(void);
michael@0 67
michael@0 68 /* --- Server state functions --------------------------------------------- */
michael@0 69 void
michael@0 70 SetServerState(char *waiter, PRInt32 state)
michael@0 71 {
michael@0 72 PR_Lock(ServerStateCVLock);
michael@0 73 ServerState = state;
michael@0 74 PR_NotifyCondVar(ServerStateCV);
michael@0 75
michael@0 76 if (debug_mode) DPRINTF("\t%s changed state to %d\n", waiter, state);
michael@0 77
michael@0 78 PR_Unlock(ServerStateCVLock);
michael@0 79 }
michael@0 80
michael@0 81 int
michael@0 82 WaitServerState(char *waiter, PRInt32 state)
michael@0 83 {
michael@0 84 PRInt32 rv;
michael@0 85
michael@0 86 PR_Lock(ServerStateCVLock);
michael@0 87
michael@0 88 if (debug_mode) DPRINTF("\t%s waiting for state %d\n", waiter, state);
michael@0 89
michael@0 90 while(!(ServerState & state))
michael@0 91 PR_WaitCondVar(ServerStateCV, PR_INTERVAL_NO_TIMEOUT);
michael@0 92 rv = ServerState;
michael@0 93
michael@0 94 if (debug_mode) DPRINTF("\t%s resuming from wait for state %d; state now %d\n",
michael@0 95 waiter, state, ServerState);
michael@0 96 PR_Unlock(ServerStateCVLock);
michael@0 97
michael@0 98 return rv;
michael@0 99 }
michael@0 100
michael@0 101 /* --- Server Functions ------------------------------------------- */
michael@0 102
michael@0 103 PRLock *workerThreadsLock;
michael@0 104 PRInt32 workerThreads;
michael@0 105 PRInt32 workerThreadsBusy;
michael@0 106
michael@0 107 void
michael@0 108 WorkerThreadFunc(void *_listenSock)
michael@0 109 {
michael@0 110 PRFileDesc *listenSock = (PRFileDesc *)_listenSock;
michael@0 111 PRInt32 bytesRead;
michael@0 112 PRInt32 bytesWritten;
michael@0 113 char *dataBuf;
michael@0 114 char *sendBuf;
michael@0 115
michael@0 116 if (debug_mode) DPRINTF("\tServer buffer is %d bytes; %d data, %d netaddrs\n",
michael@0 117 _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
michael@0 118 dataBuf = (char *)PR_MALLOC(_client_data + 2*sizeof(PRNetAddr) + 32);
michael@0 119 if (!dataBuf)
michael@0 120 if (debug_mode) printf("\tServer could not malloc space!?\n");
michael@0 121 sendBuf = (char *)PR_MALLOC(_server_data *sizeof(char));
michael@0 122 if (!sendBuf)
michael@0 123 if (debug_mode) printf("\tServer could not malloc space!?\n");
michael@0 124
michael@0 125 if (debug_mode) DPRINTF("\tServer worker thread running\n");
michael@0 126
michael@0 127 while(1) {
michael@0 128 PRInt32 bytesToRead = _client_data;
michael@0 129 PRInt32 bytesToWrite = _server_data;
michael@0 130 PRFileDesc *newSock;
michael@0 131 PRNetAddr *rAddr;
michael@0 132 PRInt32 loops = 0;
michael@0 133
michael@0 134 loops++;
michael@0 135
michael@0 136 if (debug_mode) DPRINTF("\tServer thread going into accept\n");
michael@0 137
michael@0 138 bytesRead = PR_AcceptRead(listenSock,
michael@0 139 &newSock,
michael@0 140 &rAddr,
michael@0 141 dataBuf,
michael@0 142 bytesToRead,
michael@0 143 PR_INTERVAL_NO_TIMEOUT);
michael@0 144
michael@0 145 if (bytesRead < 0) {
michael@0 146 if (debug_mode) printf("\tServer error in accept (%d)\n", bytesRead);
michael@0 147 continue;
michael@0 148 }
michael@0 149
michael@0 150 if (debug_mode) DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
michael@0 151
michael@0 152 PR_AtomicIncrement(&workerThreadsBusy);
michael@0 153 #ifdef SYMBIAN
michael@0 154 if (workerThreadsBusy == workerThreads && workerThreads<1) {
michael@0 155 #else
michael@0 156 if (workerThreadsBusy == workerThreads) {
michael@0 157 #endif
michael@0 158
michael@0 159 PR_Lock(workerThreadsLock);
michael@0 160 if (workerThreadsBusy == workerThreads) {
michael@0 161 PRThread *WorkerThread;
michael@0 162
michael@0 163 WorkerThread = PR_CreateThread(
michael@0 164 PR_SYSTEM_THREAD,
michael@0 165 WorkerThreadFunc,
michael@0 166 listenSock,
michael@0 167 PR_PRIORITY_NORMAL,
michael@0 168 ServerScope,
michael@0 169 PR_UNJOINABLE_THREAD,
michael@0 170 THREAD_STACKSIZE);
michael@0 171
michael@0 172 if (!WorkerThread) {
michael@0 173 if (debug_mode) printf("Error creating client thread %d\n", workerThreads);
michael@0 174 } else {
michael@0 175 PR_AtomicIncrement(&workerThreads);
michael@0 176 if (debug_mode) DPRINTF("\tServer creates worker (%d)\n", workerThreads);
michael@0 177 }
michael@0 178 }
michael@0 179 PR_Unlock(workerThreadsLock);
michael@0 180 }
michael@0 181
michael@0 182 bytesToRead -= bytesRead;
michael@0 183 while (bytesToRead) {
michael@0 184 bytesRead = PR_Recv(newSock,
michael@0 185 dataBuf,
michael@0 186 bytesToRead,
michael@0 187 0,
michael@0 188 PR_INTERVAL_NO_TIMEOUT);
michael@0 189 if (bytesRead < 0) {
michael@0 190 if (debug_mode) printf("\tServer error receiving data (%d)\n", bytesRead);
michael@0 191 continue;
michael@0 192 }
michael@0 193 if (debug_mode) DPRINTF("\tServer received %d bytes\n", bytesRead);
michael@0 194 }
michael@0 195
michael@0 196 bytesWritten = PR_Send(newSock,
michael@0 197 sendBuf,
michael@0 198 bytesToWrite,
michael@0 199 0,
michael@0 200 PR_INTERVAL_NO_TIMEOUT);
michael@0 201 if (bytesWritten != _server_data) {
michael@0 202 if (debug_mode) printf("\tError sending data to client (%d, %d)\n",
michael@0 203 bytesWritten, PR_GetOSError());
michael@0 204 } else {
michael@0 205 if (debug_mode) DPRINTF("\tServer sent %d bytes\n", bytesWritten);
michael@0 206 }
michael@0 207
michael@0 208 PR_Close(newSock);
michael@0 209 PR_AtomicDecrement(&workerThreadsBusy);
michael@0 210 }
michael@0 211 }
michael@0 212
michael@0 213 PRFileDesc *
michael@0 214 ServerSetup(void)
michael@0 215 {
michael@0 216 PRFileDesc *listenSocket;
michael@0 217 PRSocketOptionData sockOpt;
michael@0 218 PRNetAddr serverAddr;
michael@0 219 PRThread *WorkerThread;
michael@0 220
michael@0 221 if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
michael@0 222 if (debug_mode) printf("\tServer error creating listen socket\n");
michael@0 223 else failed_already=1;
michael@0 224 return NULL;
michael@0 225 }
michael@0 226
michael@0 227 sockOpt.option = PR_SockOpt_Reuseaddr;
michael@0 228 sockOpt.value.reuse_addr = PR_TRUE;
michael@0 229 if ( PR_SetSocketOption(listenSocket, &sockOpt) == PR_FAILURE) {
michael@0 230 if (debug_mode) printf("\tServer error setting socket option: OS error %d\n",
michael@0 231 PR_GetOSError());
michael@0 232 else failed_already=1;
michael@0 233 PR_Close(listenSocket);
michael@0 234 return NULL;
michael@0 235 }
michael@0 236
michael@0 237 memset(&serverAddr, 0, sizeof(PRNetAddr));
michael@0 238 serverAddr.inet.family = PR_AF_INET;
michael@0 239 serverAddr.inet.port = PR_htons(PORT);
michael@0 240 serverAddr.inet.ip = PR_htonl(PR_INADDR_ANY);
michael@0 241
michael@0 242 if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
michael@0 243 if (debug_mode) printf("\tServer error binding to server address: OS error %d\n",
michael@0 244 PR_GetOSError());
michael@0 245 else failed_already=1;
michael@0 246 PR_Close(listenSocket);
michael@0 247 return NULL;
michael@0 248 }
michael@0 249
michael@0 250 if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
michael@0 251 if (debug_mode) printf("\tServer error listening to server socket\n");
michael@0 252 else failed_already=1;
michael@0 253 PR_Close(listenSocket);
michael@0 254
michael@0 255 return NULL;
michael@0 256 }
michael@0 257
michael@0 258 /* Create Clients */
michael@0 259 workerThreads = 0;
michael@0 260 workerThreadsBusy = 0;
michael@0 261
michael@0 262 workerThreadsLock = PR_NewLock();
michael@0 263
michael@0 264 WorkerThread = PR_CreateThread(
michael@0 265 PR_SYSTEM_THREAD,
michael@0 266 WorkerThreadFunc,
michael@0 267 listenSocket,
michael@0 268 PR_PRIORITY_NORMAL,
michael@0 269 ServerScope,
michael@0 270 PR_UNJOINABLE_THREAD,
michael@0 271 THREAD_STACKSIZE);
michael@0 272
michael@0 273 if (!WorkerThread) {
michael@0 274 if (debug_mode) printf("error creating working thread\n");
michael@0 275 PR_Close(listenSocket);
michael@0 276 return NULL;
michael@0 277 }
michael@0 278 PR_AtomicIncrement(&workerThreads);
michael@0 279 if (debug_mode) DPRINTF("\tServer created primordial worker thread\n");
michael@0 280
michael@0 281 return listenSocket;
michael@0 282 }
michael@0 283
michael@0 284 /* The main server loop */
michael@0 285 void
michael@0 286 ServerThreadFunc(void *unused)
michael@0 287 {
michael@0 288 PRFileDesc *listenSocket;
michael@0 289
michael@0 290 /* Do setup */
michael@0 291 listenSocket = ServerSetup();
michael@0 292
michael@0 293 if (!listenSocket) {
michael@0 294 SetServerState(SERVER, SERVER_STATE_DEAD);
michael@0 295 } else {
michael@0 296
michael@0 297 if (debug_mode) DPRINTF("\tServer up\n");
michael@0 298
michael@0 299 /* Tell clients they can start now. */
michael@0 300 SetServerState(SERVER, SERVER_STATE_READY);
michael@0 301
michael@0 302 /* Now wait for server death signal */
michael@0 303 WaitServerState(SERVER, SERVER_STATE_DYING);
michael@0 304
michael@0 305 /* Cleanup */
michael@0 306 SetServerState(SERVER, SERVER_STATE_DEAD);
michael@0 307 }
michael@0 308 }
michael@0 309
michael@0 310 /* --- Client Functions ------------------------------------------- */
michael@0 311
michael@0 312 PRInt32 numRequests;
michael@0 313 PRInt32 numClients;
michael@0 314 PRMonitor *clientMonitor;
michael@0 315
michael@0 316 void
michael@0 317 ClientThreadFunc(void *unused)
michael@0 318 {
michael@0 319 PRNetAddr serverAddr;
michael@0 320 PRFileDesc *clientSocket;
michael@0 321 char *sendBuf;
michael@0 322 char *recvBuf;
michael@0 323 PRInt32 rv;
michael@0 324 PRInt32 bytesNeeded;
michael@0 325
michael@0 326 sendBuf = (char *)PR_MALLOC(_client_data * sizeof(char));
michael@0 327 if (!sendBuf)
michael@0 328 if (debug_mode) printf("\tClient could not malloc space!?\n");
michael@0 329 recvBuf = (char *)PR_MALLOC(_server_data * sizeof(char));
michael@0 330 if (!recvBuf)
michael@0 331 if (debug_mode) printf("\tClient could not malloc space!?\n");
michael@0 332
michael@0 333 memset(&serverAddr, 0, sizeof(PRNetAddr));
michael@0 334 serverAddr.inet.family = PR_AF_INET;
michael@0 335 serverAddr.inet.port = PR_htons(PORT);
michael@0 336 serverAddr.inet.ip = PR_htonl(PR_INADDR_LOOPBACK);
michael@0 337
michael@0 338 while(numRequests > 0) {
michael@0 339
michael@0 340 if ( (numRequests % 10) == 0 )
michael@0 341 if (debug_mode) printf(".");
michael@0 342 if (debug_mode) DPRINTF("\tClient starting request %d\n", numRequests);
michael@0 343
michael@0 344 clientSocket = PR_NewTCPSocket();
michael@0 345 if (!clientSocket) {
michael@0 346 if (debug_mode) printf("Client error creating socket: OS error %d\n",
michael@0 347 PR_GetOSError());
michael@0 348 continue;
michael@0 349 }
michael@0 350
michael@0 351 if (debug_mode) DPRINTF("\tClient connecting\n");
michael@0 352
michael@0 353 rv = PR_Connect(clientSocket,
michael@0 354 &serverAddr,
michael@0 355 PR_INTERVAL_NO_TIMEOUT);
michael@0 356 if (!clientSocket) {
michael@0 357 if (debug_mode) printf("\tClient error connecting\n");
michael@0 358 continue;
michael@0 359 }
michael@0 360
michael@0 361 if (debug_mode) DPRINTF("\tClient connected\n");
michael@0 362
michael@0 363 rv = PR_Send(clientSocket,
michael@0 364 sendBuf,
michael@0 365 _client_data,
michael@0 366 0,
michael@0 367 PR_INTERVAL_NO_TIMEOUT);
michael@0 368 if (rv != _client_data) {
michael@0 369 if (debug_mode) printf("Client error sending data (%d)\n", rv);
michael@0 370 PR_Close(clientSocket);
michael@0 371 continue;
michael@0 372 }
michael@0 373
michael@0 374 if (debug_mode) DPRINTF("\tClient sent %d bytes\n", rv);
michael@0 375
michael@0 376 bytesNeeded = _server_data;
michael@0 377 while(bytesNeeded) {
michael@0 378 rv = PR_Recv(clientSocket,
michael@0 379 recvBuf,
michael@0 380 bytesNeeded,
michael@0 381 0,
michael@0 382 PR_INTERVAL_NO_TIMEOUT);
michael@0 383 if (rv <= 0) {
michael@0 384 if (debug_mode) printf("Client error receiving data (%d) (%d/%d)\n",
michael@0 385 rv, (_server_data - bytesNeeded), _server_data);
michael@0 386 break;
michael@0 387 }
michael@0 388 if (debug_mode) DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
michael@0 389 bytesNeeded -= rv;
michael@0 390 }
michael@0 391
michael@0 392 PR_Close(clientSocket);
michael@0 393
michael@0 394 PR_AtomicDecrement(&numRequests);
michael@0 395 }
michael@0 396
michael@0 397 PR_EnterMonitor(clientMonitor);
michael@0 398 --numClients;
michael@0 399 PR_Notify(clientMonitor);
michael@0 400 PR_ExitMonitor(clientMonitor);
michael@0 401
michael@0 402 PR_DELETE(sendBuf);
michael@0 403 PR_DELETE(recvBuf);
michael@0 404 }
michael@0 405
michael@0 406 void
michael@0 407 RunClients(void)
michael@0 408 {
michael@0 409 PRInt32 index;
michael@0 410
michael@0 411 numRequests = _iterations;
michael@0 412 numClients = _clients;
michael@0 413 clientMonitor = PR_NewMonitor();
michael@0 414
michael@0 415 for (index=0; index<_clients; index++) {
michael@0 416 PRThread *clientThread;
michael@0 417
michael@0 418
michael@0 419 clientThread = PR_CreateThread(
michael@0 420 PR_USER_THREAD,
michael@0 421 ClientThreadFunc,
michael@0 422 NULL,
michael@0 423 PR_PRIORITY_NORMAL,
michael@0 424 ClientScope,
michael@0 425 PR_UNJOINABLE_THREAD,
michael@0 426 THREAD_STACKSIZE);
michael@0 427
michael@0 428 if (!clientThread) {
michael@0 429 if (debug_mode) printf("\terror creating client thread %d\n", index);
michael@0 430 } else
michael@0 431 if (debug_mode) DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
michael@0 432
michael@0 433 }
michael@0 434
michael@0 435 PR_EnterMonitor(clientMonitor);
michael@0 436 while(numClients)
michael@0 437 PR_Wait(clientMonitor, PR_INTERVAL_NO_TIMEOUT);
michael@0 438 PR_ExitMonitor(clientMonitor);
michael@0 439 }
michael@0 440
michael@0 441 /* --- Main Function ---------------------------------------------- */
michael@0 442
michael@0 443 static
michael@0 444 void do_work()
michael@0 445 {
michael@0 446 PRThread *ServerThread;
michael@0 447 PRInt32 state;
michael@0 448
michael@0 449 SetServerState(MAIN, SERVER_STATE_STARTUP);
michael@0 450 ServerThread = PR_CreateThread(
michael@0 451 PR_USER_THREAD,
michael@0 452 ServerThreadFunc,
michael@0 453 NULL,
michael@0 454 PR_PRIORITY_NORMAL,
michael@0 455 ServerScope,
michael@0 456 PR_JOINABLE_THREAD,
michael@0 457 THREAD_STACKSIZE);
michael@0 458 if (!ServerThread) {
michael@0 459 if (debug_mode) printf("error creating main server thread\n");
michael@0 460 return;
michael@0 461 }
michael@0 462
michael@0 463 /* Wait for server to be ready */
michael@0 464 state = WaitServerState(MAIN, SERVER_STATE_READY|SERVER_STATE_DEAD);
michael@0 465
michael@0 466 if (!(state & SERVER_STATE_DEAD)) {
michael@0 467 /* Run Test Clients */
michael@0 468 RunClients();
michael@0 469
michael@0 470 /* Send death signal to server */
michael@0 471 SetServerState(MAIN, SERVER_STATE_DYING);
michael@0 472 }
michael@0 473
michael@0 474 PR_JoinThread(ServerThread);
michael@0 475 }
michael@0 476
michael@0 477 static void do_workUU(void)
michael@0 478 {
michael@0 479 ServerScope = PR_LOCAL_THREAD;
michael@0 480 ClientScope = PR_LOCAL_THREAD;
michael@0 481 do_work();
michael@0 482 }
michael@0 483
michael@0 484
michael@0 485
michael@0 486 static void Measure(void (*func)(void), const char *msg)
michael@0 487 {
michael@0 488 PRIntervalTime start, stop;
michael@0 489 double d;
michael@0 490
michael@0 491 start = PR_IntervalNow();
michael@0 492 (*func)();
michael@0 493 stop = PR_IntervalNow();
michael@0 494
michael@0 495 d = (double)PR_IntervalToMicroseconds(stop - start);
michael@0 496
michael@0 497 if (debug_mode) printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
michael@0 498 }
michael@0 499
michael@0 500
michael@0 501 int main(int argc, char **argv)
michael@0 502 {
michael@0 503 /* The command line argument: -d is used to determine if the test is being run
michael@0 504 in debug mode. The regress tool requires only one line output:PASS or FAIL.
michael@0 505 All of the printfs associated with this test has been handled with a if (debug_mode)
michael@0 506 test.
michael@0 507 Usage: test_name -d
michael@0 508 */
michael@0 509 PLOptStatus os;
michael@0 510 PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
michael@0 511 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
michael@0 512 {
michael@0 513 if (PL_OPT_BAD == os) continue;
michael@0 514 switch (opt->option)
michael@0 515 {
michael@0 516 case 'd': /* debug mode */
michael@0 517 debug_mode = 1;
michael@0 518 break;
michael@0 519 default:
michael@0 520 break;
michael@0 521 }
michael@0 522 }
michael@0 523 PL_DestroyOptState(opt);
michael@0 524
michael@0 525 /* main test */
michael@0 526 #ifndef SYMBIAN
michael@0 527 if (debug_mode) {
michael@0 528 printf("Enter number of iterations: \n");
michael@0 529 scanf("%d", &_iterations);
michael@0 530 printf("Enter number of clients : \n");
michael@0 531 scanf("%d", &_clients);
michael@0 532 printf("Enter size of client data : \n");
michael@0 533 scanf("%d", &_client_data);
michael@0 534 printf("Enter size of server data : \n");
michael@0 535 scanf("%d", &_server_data);
michael@0 536 }
michael@0 537 else
michael@0 538 #endif
michael@0 539 {
michael@0 540 _iterations = 7;
michael@0 541 _clients = 7;
michael@0 542 _client_data = 100;
michael@0 543 _server_data = 100;
michael@0 544 }
michael@0 545
michael@0 546 if (debug_mode) {
michael@0 547 printf("\n\n%d iterations with %d client threads.\n",
michael@0 548 _iterations, _clients);
michael@0 549 printf("Sending %d bytes of client data and %d bytes of server data\n",
michael@0 550 _client_data, _server_data);
michael@0 551 }
michael@0 552 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
michael@0 553 PR_STDIO_INIT();
michael@0 554
michael@0 555 PR_SetThreadRecycleMode(64);
michael@0 556
michael@0 557 ServerStateCVLock = PR_NewLock();
michael@0 558 ServerStateCV = PR_NewCondVar(ServerStateCVLock);
michael@0 559
michael@0 560 Measure(do_workUU, "server loop user/user");
michael@0 561
michael@0 562 PR_Cleanup();
michael@0 563
michael@0 564 if(failed_already)
michael@0 565 return 1;
michael@0 566 else
michael@0 567 return 0;
michael@0 568
michael@0 569 }

mercurial