nsprpub/pr/tests/servr_ku.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 PR_Lock(workerThreadsLock);
michael@0 159 if (workerThreadsBusy == workerThreads) {
michael@0 160 PRThread *WorkerThread;
michael@0 161
michael@0 162 WorkerThread = PR_CreateThread(
michael@0 163 PR_SYSTEM_THREAD,
michael@0 164 WorkerThreadFunc,
michael@0 165 listenSock,
michael@0 166 PR_PRIORITY_NORMAL,
michael@0 167 ServerScope,
michael@0 168 PR_UNJOINABLE_THREAD,
michael@0 169 THREAD_STACKSIZE);
michael@0 170
michael@0 171 if (!WorkerThread) {
michael@0 172 if (debug_mode) printf("Error creating client thread %d\n", workerThreads);
michael@0 173 } else {
michael@0 174 PR_AtomicIncrement(&workerThreads);
michael@0 175 if (debug_mode) DPRINTF("\tServer creates worker (%d)\n", workerThreads);
michael@0 176 }
michael@0 177 }
michael@0 178 PR_Unlock(workerThreadsLock);
michael@0 179 }
michael@0 180
michael@0 181 bytesToRead -= bytesRead;
michael@0 182 while (bytesToRead) {
michael@0 183 bytesRead = PR_Recv(newSock,
michael@0 184 dataBuf,
michael@0 185 bytesToRead,
michael@0 186 0,
michael@0 187 PR_INTERVAL_NO_TIMEOUT);
michael@0 188 if (bytesRead < 0) {
michael@0 189 if (debug_mode) printf("\tServer error receiving data (%d)\n", bytesRead);
michael@0 190 continue;
michael@0 191 }
michael@0 192 if (debug_mode) DPRINTF("\tServer received %d bytes\n", bytesRead);
michael@0 193 }
michael@0 194
michael@0 195 bytesWritten = PR_Send(newSock,
michael@0 196 sendBuf,
michael@0 197 bytesToWrite,
michael@0 198 0,
michael@0 199 PR_INTERVAL_NO_TIMEOUT);
michael@0 200 if (bytesWritten != _server_data) {
michael@0 201 if (debug_mode) printf("\tError sending data to client (%d, %d)\n",
michael@0 202 bytesWritten, PR_GetOSError());
michael@0 203 } else {
michael@0 204 if (debug_mode) DPRINTF("\tServer sent %d bytes\n", bytesWritten);
michael@0 205 }
michael@0 206
michael@0 207 PR_Close(newSock);
michael@0 208 PR_AtomicDecrement(&workerThreadsBusy);
michael@0 209 }
michael@0 210 }
michael@0 211
michael@0 212 PRFileDesc *
michael@0 213 ServerSetup(void)
michael@0 214 {
michael@0 215 PRFileDesc *listenSocket;
michael@0 216 PRSocketOptionData sockOpt;
michael@0 217 PRNetAddr serverAddr;
michael@0 218 PRThread *WorkerThread;
michael@0 219
michael@0 220 if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
michael@0 221 if (debug_mode) printf("\tServer error creating listen socket\n");
michael@0 222 else failed_already=1;
michael@0 223 return NULL;
michael@0 224 }
michael@0 225
michael@0 226 sockOpt.option = PR_SockOpt_Reuseaddr;
michael@0 227 sockOpt.value.reuse_addr = PR_TRUE;
michael@0 228 if ( PR_SetSocketOption(listenSocket, &sockOpt) == PR_FAILURE) {
michael@0 229 if (debug_mode) printf("\tServer error setting socket option: OS error %d\n",
michael@0 230 PR_GetOSError());
michael@0 231 else failed_already=1;
michael@0 232 PR_Close(listenSocket);
michael@0 233 return NULL;
michael@0 234 }
michael@0 235
michael@0 236 memset(&serverAddr, 0, sizeof(PRNetAddr));
michael@0 237 serverAddr.inet.family = PR_AF_INET;
michael@0 238 serverAddr.inet.port = PR_htons(PORT);
michael@0 239 serverAddr.inet.ip = PR_htonl(PR_INADDR_ANY);
michael@0 240
michael@0 241 if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
michael@0 242 if (debug_mode) printf("\tServer error binding to server address: OS error %d\n",
michael@0 243 PR_GetOSError());
michael@0 244 else failed_already=1;
michael@0 245 PR_Close(listenSocket);
michael@0 246 return NULL;
michael@0 247 }
michael@0 248
michael@0 249 if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
michael@0 250 if (debug_mode) printf("\tServer error listening to server socket\n");
michael@0 251 else failed_already=1;
michael@0 252 PR_Close(listenSocket);
michael@0 253
michael@0 254 return NULL;
michael@0 255 }
michael@0 256
michael@0 257 /* Create Clients */
michael@0 258 workerThreads = 0;
michael@0 259 workerThreadsBusy = 0;
michael@0 260
michael@0 261 workerThreadsLock = PR_NewLock();
michael@0 262
michael@0 263 WorkerThread = PR_CreateThread(
michael@0 264 PR_SYSTEM_THREAD,
michael@0 265 WorkerThreadFunc,
michael@0 266 listenSocket,
michael@0 267 PR_PRIORITY_NORMAL,
michael@0 268 ServerScope,
michael@0 269 PR_UNJOINABLE_THREAD,
michael@0 270 THREAD_STACKSIZE);
michael@0 271
michael@0 272 if (!WorkerThread) {
michael@0 273 if (debug_mode) printf("error creating working thread\n");
michael@0 274 PR_Close(listenSocket);
michael@0 275 return NULL;
michael@0 276 }
michael@0 277 PR_AtomicIncrement(&workerThreads);
michael@0 278 if (debug_mode) DPRINTF("\tServer created primordial worker thread\n");
michael@0 279
michael@0 280 return listenSocket;
michael@0 281 }
michael@0 282
michael@0 283 /* The main server loop */
michael@0 284 void
michael@0 285 ServerThreadFunc(void *unused)
michael@0 286 {
michael@0 287 PRFileDesc *listenSocket;
michael@0 288
michael@0 289 /* Do setup */
michael@0 290 listenSocket = ServerSetup();
michael@0 291
michael@0 292 if (!listenSocket) {
michael@0 293 SetServerState(SERVER, SERVER_STATE_DEAD);
michael@0 294 } else {
michael@0 295
michael@0 296 if (debug_mode) DPRINTF("\tServer up\n");
michael@0 297
michael@0 298 /* Tell clients they can start now. */
michael@0 299 SetServerState(SERVER, SERVER_STATE_READY);
michael@0 300
michael@0 301 /* Now wait for server death signal */
michael@0 302 WaitServerState(SERVER, SERVER_STATE_DYING);
michael@0 303
michael@0 304 /* Cleanup */
michael@0 305 SetServerState(SERVER, SERVER_STATE_DEAD);
michael@0 306 }
michael@0 307 }
michael@0 308
michael@0 309 /* --- Client Functions ------------------------------------------- */
michael@0 310
michael@0 311 PRInt32 numRequests;
michael@0 312 PRInt32 numClients;
michael@0 313 PRMonitor *clientMonitor;
michael@0 314
michael@0 315 void
michael@0 316 ClientThreadFunc(void *unused)
michael@0 317 {
michael@0 318 PRNetAddr serverAddr;
michael@0 319 PRFileDesc *clientSocket;
michael@0 320 char *sendBuf;
michael@0 321 char *recvBuf;
michael@0 322 PRInt32 rv;
michael@0 323 PRInt32 bytesNeeded;
michael@0 324
michael@0 325 sendBuf = (char *)PR_MALLOC(_client_data * sizeof(char));
michael@0 326 if (!sendBuf)
michael@0 327 if (debug_mode) printf("\tClient could not malloc space!?\n");
michael@0 328 recvBuf = (char *)PR_MALLOC(_server_data * sizeof(char));
michael@0 329 if (!recvBuf)
michael@0 330 if (debug_mode) printf("\tClient could not malloc space!?\n");
michael@0 331
michael@0 332 memset(&serverAddr, 0, sizeof(PRNetAddr));
michael@0 333 serverAddr.inet.family = PR_AF_INET;
michael@0 334 serverAddr.inet.port = PR_htons(PORT);
michael@0 335 serverAddr.inet.ip = PR_htonl(PR_INADDR_LOOPBACK);
michael@0 336
michael@0 337 while(numRequests > 0) {
michael@0 338
michael@0 339 if ( (numRequests % 10) == 0 )
michael@0 340 if (debug_mode) printf(".");
michael@0 341 if (debug_mode) DPRINTF("\tClient starting request %d\n", numRequests);
michael@0 342
michael@0 343 clientSocket = PR_NewTCPSocket();
michael@0 344 if (!clientSocket) {
michael@0 345 if (debug_mode) printf("Client error creating socket: OS error %d\n",
michael@0 346 PR_GetOSError());
michael@0 347 continue;
michael@0 348 }
michael@0 349
michael@0 350 if (debug_mode) DPRINTF("\tClient connecting\n");
michael@0 351
michael@0 352 rv = PR_Connect(clientSocket,
michael@0 353 &serverAddr,
michael@0 354 PR_INTERVAL_NO_TIMEOUT);
michael@0 355 if (!clientSocket) {
michael@0 356 if (debug_mode) printf("\tClient error connecting\n");
michael@0 357 continue;
michael@0 358 }
michael@0 359
michael@0 360 if (debug_mode) DPRINTF("\tClient connected\n");
michael@0 361
michael@0 362 rv = PR_Send(clientSocket,
michael@0 363 sendBuf,
michael@0 364 _client_data,
michael@0 365 0,
michael@0 366 PR_INTERVAL_NO_TIMEOUT);
michael@0 367 if (rv != _client_data) {
michael@0 368 if (debug_mode) printf("Client error sending data (%d)\n", rv);
michael@0 369 PR_Close(clientSocket);
michael@0 370 continue;
michael@0 371 }
michael@0 372
michael@0 373 if (debug_mode) DPRINTF("\tClient sent %d bytes\n", rv);
michael@0 374
michael@0 375 bytesNeeded = _server_data;
michael@0 376 while(bytesNeeded) {
michael@0 377 rv = PR_Recv(clientSocket,
michael@0 378 recvBuf,
michael@0 379 bytesNeeded,
michael@0 380 0,
michael@0 381 PR_INTERVAL_NO_TIMEOUT);
michael@0 382 if (rv <= 0) {
michael@0 383 if (debug_mode) printf("Client error receiving data (%d) (%d/%d)\n",
michael@0 384 rv, (_server_data - bytesNeeded), _server_data);
michael@0 385 break;
michael@0 386 }
michael@0 387 if (debug_mode) DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
michael@0 388 bytesNeeded -= rv;
michael@0 389 }
michael@0 390
michael@0 391 PR_Close(clientSocket);
michael@0 392
michael@0 393 PR_AtomicDecrement(&numRequests);
michael@0 394 }
michael@0 395
michael@0 396 PR_EnterMonitor(clientMonitor);
michael@0 397 --numClients;
michael@0 398 PR_Notify(clientMonitor);
michael@0 399 PR_ExitMonitor(clientMonitor);
michael@0 400
michael@0 401 PR_DELETE(sendBuf);
michael@0 402 PR_DELETE(recvBuf);
michael@0 403 }
michael@0 404
michael@0 405 void
michael@0 406 RunClients(void)
michael@0 407 {
michael@0 408 PRInt32 index;
michael@0 409
michael@0 410 numRequests = _iterations;
michael@0 411 numClients = _clients;
michael@0 412 clientMonitor = PR_NewMonitor();
michael@0 413
michael@0 414 for (index=0; index<_clients; index++) {
michael@0 415 PRThread *clientThread;
michael@0 416
michael@0 417
michael@0 418 clientThread = PR_CreateThread(
michael@0 419 PR_USER_THREAD,
michael@0 420 ClientThreadFunc,
michael@0 421 NULL,
michael@0 422 PR_PRIORITY_NORMAL,
michael@0 423 ClientScope,
michael@0 424 PR_UNJOINABLE_THREAD,
michael@0 425 THREAD_STACKSIZE);
michael@0 426
michael@0 427 if (!clientThread) {
michael@0 428 if (debug_mode) printf("\terror creating client thread %d\n", index);
michael@0 429 } else
michael@0 430 if (debug_mode) DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
michael@0 431
michael@0 432 }
michael@0 433
michael@0 434 PR_EnterMonitor(clientMonitor);
michael@0 435 while(numClients)
michael@0 436 PR_Wait(clientMonitor, PR_INTERVAL_NO_TIMEOUT);
michael@0 437 PR_ExitMonitor(clientMonitor);
michael@0 438 }
michael@0 439
michael@0 440 /* --- Main Function ---------------------------------------------- */
michael@0 441
michael@0 442 static
michael@0 443 void do_work()
michael@0 444 {
michael@0 445 PRThread *ServerThread;
michael@0 446 PRInt32 state;
michael@0 447
michael@0 448 SetServerState(MAIN, SERVER_STATE_STARTUP);
michael@0 449 ServerThread = PR_CreateThread(
michael@0 450 PR_USER_THREAD,
michael@0 451 ServerThreadFunc,
michael@0 452 NULL,
michael@0 453 PR_PRIORITY_NORMAL,
michael@0 454 ServerScope,
michael@0 455 PR_JOINABLE_THREAD,
michael@0 456 THREAD_STACKSIZE);
michael@0 457 if (!ServerThread) {
michael@0 458 if (debug_mode) printf("error creating main server thread\n");
michael@0 459 return;
michael@0 460 }
michael@0 461
michael@0 462 /* Wait for server to be ready */
michael@0 463 state = WaitServerState(MAIN, SERVER_STATE_READY|SERVER_STATE_DEAD);
michael@0 464
michael@0 465 if (!(state & SERVER_STATE_DEAD)) {
michael@0 466 /* Run Test Clients */
michael@0 467 RunClients();
michael@0 468
michael@0 469 /* Send death signal to server */
michael@0 470 SetServerState(MAIN, SERVER_STATE_DYING);
michael@0 471 }
michael@0 472
michael@0 473 PR_JoinThread(ServerThread);
michael@0 474 }
michael@0 475
michael@0 476
michael@0 477 static void do_workKU(void)
michael@0 478 {
michael@0 479 ServerScope = PR_GLOBAL_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_workKU, "server loop kernel/user");
michael@0 561
michael@0 562 PR_Cleanup();
michael@0 563 if(failed_already)
michael@0 564 return 1;
michael@0 565 else
michael@0 566 return 0;
michael@0 567
michael@0 568 }

mercurial