diff options
Diffstat (limited to 'pr/tests/udpsrv.c')
-rw-r--r-- | pr/tests/udpsrv.c | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/pr/tests/udpsrv.c b/pr/tests/udpsrv.c index 805bccbb..d8aa208f 100644 --- a/pr/tests/udpsrv.c +++ b/pr/tests/udpsrv.c @@ -22,21 +22,21 @@ ** He detects an EOF condition set by UDP_Client(). For each ** packet received by UDP_Server(), he checks its content for ** expected content, then sends the packet back to UDP_Client(). -** +** ** UDP_Client() sends packets to UDP_Server() using sendto() ** he recieves packets back from the server via recvfrom(). ** After he sends enough packets containing UDP_AMOUNT_TO_WRITE ** bytes of data, he sends an EOF message. -** +** ** The test issues a pass/fail message at end. -** +** ** Notes: ** The variable "_debug_on" can be set to 1 to cause diagnostic ** messages related to client/server synchronization. Useful when ** the test hangs. -** +** ** Error messages are written to stdout. -** +** ******************************************************************** */ /* --- include files --- */ @@ -96,11 +96,11 @@ static PRFileDesc *output = NULL; void ListNetAddr( char *msg, PRNetAddr *na ) { char mbuf[256]; - + sprintf( mbuf, "ListNetAddr: %s family: %d, port: %d, ip: %8.8X\n", msg, na->inet.family, PR_ntohs( na->inet.port), PR_ntohl(na->inet.ip) ); -#if 0 - DPRINTF( mbuf ); +#if 0 + DPRINTF( mbuf ); #endif } /* --- end ListNetAddr() --- */ @@ -127,7 +127,7 @@ static void PR_CALLBACK UDP_Server( void *arg ) PRBool bound = PR_FALSE; PRBool endOfInput = PR_FALSE; PRInt32 numBytes = UDP_DGRAM_SIZE; - + DPRINTF("udpsrv: UDP_Server(): starting\n" ); /* --- Create the socket --- */ @@ -141,13 +141,13 @@ static void PR_CALLBACK UDP_Server( void *arg ) "udpsrv: UDP_Server(): PR_NewUDPSocket() returned NULL\n" ); return; } - + /* --- Initialize the sockaddr_in structure --- */ - memset( &netaddr, 0, sizeof( netaddr )); + memset( &netaddr, 0, sizeof( netaddr )); netaddr.inet.family = PR_AF_INET; netaddr.inet.port = PR_htons( UDP_SERVER_PORT ); netaddr.inet.ip = PR_htonl( MY_INADDR ); - + /* --- Bind the socket --- */ while ( !bound ) { @@ -176,7 +176,7 @@ static void PR_CALLBACK UDP_Server( void *arg ) bound = PR_TRUE; } ListNetAddr( "UDP_Server: after bind", &netaddr ); - + /* --- Recv the socket --- */ while( !endOfInput ) { @@ -193,15 +193,15 @@ static void PR_CALLBACK UDP_Server( void *arg ) return; } ListNetAddr( "UDP_Server after RecvFrom", &netaddr ); - + srvBytesRead += rv; - + if ( svrBuf[0] == 'E' ) { DPRINTF("udpsrv: UDP_Server(): EOF on input detected\n" ); endOfInput = PR_TRUE; } - + /* --- Send the socket --- */ DPRINTF("udpsrv: UDP_Server(): SendTo(): socket\n" ); rv = PR_SendTo( svrSock, svrBuf, rv, 0, &netaddr, PR_INTERVAL_NO_TIMEOUT ); @@ -217,7 +217,7 @@ static void PR_CALLBACK UDP_Server( void *arg ) } ListNetAddr( "UDP_Server after SendTo", &netaddr ); } - + /* --- Close the socket --- */ DPRINTF("udpsrv: UDP_Server(): Closing socket\n" ); rv = PR_Close( svrSock ); @@ -229,7 +229,7 @@ static void PR_CALLBACK UDP_Server( void *arg ) "udpsrv: UDP_Server(): PR_Close(): failed to close socket\n" ); return; } - + DPRINTF("udpsrv: UDP_Server(): Normal end\n" ); } /* --- end UDP_Server() --- */ @@ -264,10 +264,10 @@ static void PR_CALLBACK UDP_Client( void *arg ) PRInt32 numBytes = UDP_DGRAM_SIZE; PRInt32 writeThisMany = UDP_AMOUNT_TO_WRITE; int i; - - + + DPRINTF("udpsrv: UDP_Client(): starting\n" ); - + /* --- Create the socket --- */ cltSock = PR_NewUDPSocket(); if ( cltSock == NULL ) @@ -278,17 +278,17 @@ static void PR_CALLBACK UDP_Client( void *arg ) "udpsrv: UDP_Client(): PR_NewUDPSocket() returned NULL\n" ); return; } - + /* --- Initialize the sockaddr_in structure --- */ - memset( &netaddr, 0, sizeof( netaddr )); + memset( &netaddr, 0, sizeof( netaddr )); netaddr.inet.family = PR_AF_INET; netaddr.inet.ip = PR_htonl( MY_INADDR ); netaddr.inet.port = PR_htons( UDP_CLIENT_PORT ); - - /* --- Initialize the write buffer --- */ + + /* --- Initialize the write buffer --- */ for ( i = 0; i < UDP_BUF_SIZE ; i++ ) cltBuf[i] = i; - + /* --- Bind the socket --- */ while ( !bound ) { @@ -319,26 +319,26 @@ static void PR_CALLBACK UDP_Client( void *arg ) bound = PR_TRUE; } ListNetAddr( "UDP_Client after Bind", &netaddr ); - + /* --- Initialize the sockaddr_in structure --- */ - memset( &netaddr, 0, sizeof( netaddr )); + memset( &netaddr, 0, sizeof( netaddr )); netaddr.inet.family = PR_AF_INET; netaddr.inet.ip = PR_htonl( PEER_INADDR ); netaddr.inet.port = PR_htons( UDP_SERVER_PORT ); - - /* --- send and receive packets until no more data left */ + + /* --- send and receive packets until no more data left */ while( !endOfInput ) { /* ** Signal EOF in the data stream on the last packet - */ + */ if ( writeThisMany <= UDP_DGRAM_SIZE ) { DPRINTF("udpsrv: UDP_Client(): Send EOF packet\n" ); cltBuf[0] = 'E'; endOfInput = PR_TRUE; } - + /* --- SendTo the socket --- */ if ( writeThisMany > UDP_DGRAM_SIZE ) numBytes = UDP_DGRAM_SIZE; @@ -347,11 +347,11 @@ static void PR_CALLBACK UDP_Client( void *arg ) writeThisMany -= numBytes; { char mbuf[256]; - sprintf( mbuf, "udpsrv: UDP_Client(): write_this_many: %d, numbytes: %d\n", + sprintf( mbuf, "udpsrv: UDP_Client(): write_this_many: %d, numbytes: %d\n", writeThisMany, numBytes ); DPRINTF( mbuf ); } - + DPRINTF("udpsrv: UDP_Client(): SendTo(): socket\n" ); rv = PR_SendTo( cltSock, cltBuf, numBytes, 0, &netaddr, UDP_TIMEOUT ); if ( rv == -1 ) @@ -381,7 +381,7 @@ static void PR_CALLBACK UDP_Client( void *arg ) } ListNetAddr( "UDP_Client after RecvFrom()", &netaddr ); cltBytesRead += rv; - + /* --- verify buffer --- */ for ( i = 0; i < rv ; i++ ) { @@ -399,7 +399,7 @@ static void PR_CALLBACK UDP_Client( void *arg ) } if (debug_mode) PR_fprintf(output, "."); } - + /* --- Close the socket --- */ DPRINTF("udpsrv: UDP_Server(): Closing socket\n" ); rv = PR_Close( cltSock ); @@ -458,16 +458,16 @@ int main(int argc, char **argv) } } PL_DestroyOptState(opt); - + PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); PR_STDIO_INIT(); output = PR_STDERR; PR_SetConcurrency(4); - + /* ** Create the Server thread - */ + */ DPRINTF( "udpsrv: Creating Server Thread\n" ); srv = PR_CreateThread( PR_USER_THREAD, UDP_Server, @@ -481,16 +481,16 @@ int main(int argc, char **argv) if (debug_mode) PR_fprintf(output, "udpsrv: Cannot create server thread\n" ); passed = PR_FALSE; } - + /* ** Give the Server time to Start - */ + */ DPRINTF( "udpsrv: Pausing to allow Server to start\n" ); PR_Sleep( PR_MillisecondsToInterval(200) ); - + /* ** Create the Client thread - */ + */ DPRINTF( "udpsrv: Creating Client Thread\n" ); clt = PR_CreateThread( PR_USER_THREAD, UDP_Client, @@ -504,14 +504,14 @@ int main(int argc, char **argv) if (debug_mode) PR_fprintf(output, "udpsrv: Cannot create server thread\n" ); passed = PR_FALSE; } - + /* ** */ DPRINTF("udpsrv: Waiting to join Server & Client Threads\n" ); PR_JoinThread( srv ); - PR_JoinThread( clt ); - + PR_JoinThread( clt ); + /* ** Evaluate test results */ |