summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/tests/ntioto.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/tests/ntioto.c')
-rw-r--r--nsprpub/pr/tests/ntioto.c141
1 files changed, 81 insertions, 60 deletions
diff --git a/nsprpub/pr/tests/ntioto.c b/nsprpub/pr/tests/ntioto.c
index 7af659445..5fb01e760 100644
--- a/nsprpub/pr/tests/ntioto.c
+++ b/nsprpub/pr/tests/ntioto.c
@@ -5,7 +5,7 @@
/*
** File: ntioto.c
-** Description:
+** Description:
** This test, ntioto.c, was designed to reproduce a bug reported by NES
** on WindowsNT (fibers implementation). NSPR was asserting in ntio.c
** after PR_AcceptRead() had timed out. I/O performed subsequent to the
@@ -16,12 +16,12 @@
** Design:
** This test will fail with an assert in ntio.c if the problem it was
** designed to catch occurs. It returns 0 otherwise.
-**
+**
** The main() thread initializes and tears things down. A file is
** opened for writing; this file will be written to by AcceptThread()
** and JitterThread(). Main() creates a socket for reading, listens
** and binds the socket.
-**
+**
** ConnectThread() connects to the socket created by main, then polls
** the "state" variable. When state is AllDone, ConnectThread() exits.
**
@@ -36,11 +36,11 @@
** AcceptThread() and JitterThread() or may take a while. The default
** iteration count, jitter, is set by DEFAULT_JITTER. This may be
** modified at the command line with the -j option.
-**
+**
*/
-#include <plgetopt.h>
-#include <nspr.h>
+#include <plgetopt.h>
+#include <nspr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -97,28 +97,37 @@ static void AcceptThread(void *arg)
PRFileDesc *arSock;
PRNetAddr *arAddr;
- bytesRead = PR_AcceptRead( listenSock,
- &arSock,
- &arAddr,
- dataBuf,
- ACCEPT_READ_DATASIZE,
- PR_SecondsToInterval(1));
+ bytesRead = PR_AcceptRead( listenSock,
+ &arSock,
+ &arAddr,
+ dataBuf,
+ ACCEPT_READ_DATASIZE,
+ PR_SecondsToInterval(1));
if ( bytesRead == -1 && PR_GetError() == PR_IO_TIMEOUT_ERROR ) {
- if ( debug ) printf("AcceptRead timed out\n");
+ if ( debug ) {
+ printf("AcceptRead timed out\n");
+ }
} else {
- if ( debug ) printf("Oops! read: %d, error: %d\n", bytesRead, PR_GetError());
+ if ( debug ) {
+ printf("Oops! read: %d, error: %d\n", bytesRead, PR_GetError());
+ }
}
while( state != AllDone ) {
PR_Lock( ml );
- while( state != RunAcceptRead )
+ while( state != RunAcceptRead ) {
PR_WaitCondVar( cv, PR_INTERVAL_NO_TIMEOUT );
- if ( ++iCounter >= jitter )
+ }
+ if ( ++iCounter >= jitter ) {
state = AllDone;
- else
+ }
+ else {
state = RunJitter;
- if ( verbose ) printf(".");
+ }
+ if ( verbose ) {
+ printf(".");
+ }
PR_NotifyCondVar( cv );
PR_Unlock( ml );
PR_Write( file1, ".", 1 );
@@ -131,11 +140,15 @@ static void JitterThread(void *arg)
{
while( state != AllDone ) {
PR_Lock( ml );
- while( state != RunJitter && state != AllDone )
+ while( state != RunJitter && state != AllDone ) {
PR_WaitCondVar( cv, PR_INTERVAL_NO_TIMEOUT );
- if ( state != AllDone)
+ }
+ if ( state != AllDone) {
state = RunAcceptRead;
- if ( verbose ) printf("+");
+ }
+ if ( verbose ) {
+ printf("+");
+ }
PR_NotifyCondVar( cv );
PR_Unlock( ml );
PR_Write( file1, "+", 1 );
@@ -153,21 +166,24 @@ static void ConnectThread( void *arg )
PR_ASSERT(clientSock);
if ( resume ) {
- if ( debug ) printf("pausing 3 seconds before connect\n");
+ if ( debug ) {
+ printf("pausing 3 seconds before connect\n");
+ }
PR_Sleep( PR_SecondsToInterval(3));
}
memset(&serverAddress, 0, sizeof(serverAddress));
rv = PR_InitializeNetAddr(PR_IpAddrLoopback, BASE_PORT, &serverAddress);
PR_ASSERT( PR_SUCCESS == rv );
- rv = PR_Connect( clientSock,
- &serverAddress,
- PR_SecondsToInterval(1));
+ rv = PR_Connect( clientSock,
+ &serverAddress,
+ PR_SecondsToInterval(1));
PR_ASSERT( PR_SUCCESS == rv );
/* that's all we do. ... Wait for the acceptread() to timeout */
- while( state != AllDone )
+ while( state != AllDone ) {
PR_Sleep( PR_SecondsToInterval(1));
+ }
return;
} /* end ConnectThread() */
@@ -191,35 +207,38 @@ int main(int argc, char **argv)
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "hdrvj:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'd': /* debug */
- debug = 1;
- msgLevel = PR_LOG_ERROR;
- break;
- case 'v': /* verbose mode */
- verbose = 1;
- msgLevel = PR_LOG_DEBUG;
- break;
- case 'j':
- jitter = atoi(opt->value);
- if ( jitter == 0)
- jitter = JITTER_DEFAULT;
- break;
- case 'r':
- resume = PR_TRUE;
- break;
- case 'h': /* help message */
- Help();
- break;
- default:
- break;
+ case 'd': /* debug */
+ debug = 1;
+ msgLevel = PR_LOG_ERROR;
+ break;
+ case 'v': /* verbose mode */
+ verbose = 1;
+ msgLevel = PR_LOG_DEBUG;
+ break;
+ case 'j':
+ jitter = atoi(opt->value);
+ if ( jitter == 0) {
+ jitter = JITTER_DEFAULT;
+ }
+ break;
+ case 'r':
+ resume = PR_TRUE;
+ break;
+ case 'h': /* help message */
+ Help();
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
lm = PR_NewLogModule("Test"); /* Initialize logging */
@@ -250,23 +269,23 @@ int main(int argc, char **argv)
/* create Connect thread */
tConnect = PR_CreateThread(
- PR_USER_THREAD, ConnectThread, NULL,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD, 0 );
+ PR_USER_THREAD, ConnectThread, NULL,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD, 0 );
PR_ASSERT( tConnect );
/* create jitter off thread */
tJitter = PR_CreateThread(
- PR_USER_THREAD, JitterThread, NULL,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD, 0 );
+ PR_USER_THREAD, JitterThread, NULL,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD, 0 );
PR_ASSERT( tJitter );
/* create acceptread thread */
tAccept = PR_CreateThread(
- PR_USER_THREAD, AcceptThread, NULL,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD, 0 );
+ PR_USER_THREAD, AcceptThread, NULL,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD, 0 );
PR_ASSERT( tAccept );
/* wait for all threads to quit, then terminate gracefully */
@@ -280,7 +299,9 @@ int main(int argc, char **argv)
PR_Delete( "xxxTestFile");
/* test return and exit */
- if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ if (debug) {
+ printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ }
return( (failed_already == PR_TRUE )? 1 : 0 );
} /* main() */
/* end ntioto.c */