accept.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/***********************************************************************
** 1996 - Netscape Communications Corporation
**
** Name: accept.c
**
** Description: Run accept() sucessful connection tests.
**
** Modification History:
** 04-Jun-97 AGarcia - Reconvert test file to return a 0 for PASS and a 1 for FAIL
** 13-May-97 AGarcia- Converted the test to accomodate the debug_mode
** 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.
** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
** recognize the return code from tha main program.
** 12-June-97 Revert to return code 0 and 1.
***********************************************************************/
/***********************************************************************
** Includes
***********************************************************************/
#include "nspr.h"
#include "prpriv.h"
#include <stdlib.h>
#include <string.h>
#include "plgetopt.h"
#include "plerror.h"
#define BASE_PORT 10000
#define CLIENT_DATA 128
#define ACCEPT_NORMAL 0x1
#define ACCEPT_FAST 0x2
#define ACCEPT_READ 0x3
#define ACCEPT_READ_FAST 0x4
#define ACCEPT_READ_FAST_CB 0x5
#define CLIENT_NORMAL 0x1
#define CLIENT_TIMEOUT_ACCEPT 0x2
#define CLIENT_TIMEOUT_SEND 0x3
#define SERVER_MAX_BIND_COUNT 100
#define TIMEOUTSECS 10
#else
#define TIMEOUTSECS 2
#endif
static PRFileDesc *output;
static PRNetAddr serverAddr;
static PRInt32 clientCommand;
static PRInt32 iterations;
static PRFileDesc *listenSock;
static PRNetAddr listenAddr;
static PRNetAddr clientAddr;
static PRThread *clientThread;
{
if (debug_mode) {
}
} /* Test_Assert */
#define TEST_ASSERT(expr) \
#ifdef WINNT
#define CALLBACK_MAGIC 0x12345678
void timeout_callback(void *magic)
{
if (debug_mode)
}
#endif
static void PR_CALLBACK
ClientThread(void *_action)
{
for (; iterations--;) {
char buf[CLIENT_DATA];
sock = PR_NewTCPSocket();
if (!sock) {
if (!debug_mode)
else
return;
}
if (action != CLIENT_TIMEOUT_ACCEPT) {
timeoutTime)) < 0) {
if (!debug_mode)
else
"client: unable to connect to server (%ld, %ld, %ld, %ld)\n",
goto ErrorExit;
}
if (action != CLIENT_TIMEOUT_SEND) {
0, timeoutTime))< 0) {
if (!debug_mode)
else
"client: unable to send to server (%d, %ld, %ld)\n",
goto ErrorExit;
}
} else {
}
} else {
}
if (debug_mode)
}
if (debug_mode)
}
static void
{
int i;
/* First bind to the socket */
if (!listenSock) {
if (debug_mode)
return;
}
/*
* try a few times to bind server's address, if addresses are in
* use
*/
i = 0;
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
if (i++ < SERVER_MAX_BIND_COUNT)
continue;
}
if (debug_mode)
return;
}
if (rv == PR_FAILURE) {
if (debug_mode)
return;
}
PR_JOINABLE_THREAD, 0);
if (!clientThread) {
if (debug_mode)
return;
}
iterations = count;
for (;iterations--;) {
switch (acceptType) {
case ACCEPT_NORMAL:
switch(clientAction) {
case CLIENT_TIMEOUT_ACCEPT:
TEST_ASSERT(clientSock == 0);
break;
case CLIENT_NORMAL:
break;
case CLIENT_TIMEOUT_SEND:
break;
}
break;
case ACCEPT_READ:
switch(clientAction) {
case CLIENT_TIMEOUT_ACCEPT:
/* Invalid test case */
TEST_ASSERT(0);
break;
case CLIENT_NORMAL:
break;
case CLIENT_TIMEOUT_SEND:
break;
}
break;
#ifdef WINNT
case ACCEPT_FAST:
switch(clientAction) {
case CLIENT_TIMEOUT_ACCEPT:
TEST_ASSERT(clientSock == 0);
if (debug_mode)
break;
case CLIENT_NORMAL:
break;
case CLIENT_TIMEOUT_SEND:
break;
}
break;
break;
case ACCEPT_READ_FAST:
switch(clientAction) {
case CLIENT_TIMEOUT_ACCEPT:
/* Invalid test case */
TEST_ASSERT(0);
break;
case CLIENT_NORMAL:
break;
case CLIENT_TIMEOUT_SEND:
break;
}
break;
case ACCEPT_READ_FAST_CB:
switch(clientAction) {
case CLIENT_TIMEOUT_ACCEPT:
/* Invalid test case */
TEST_ASSERT(0);
break;
case CLIENT_NORMAL:
break;
case CLIENT_TIMEOUT_SEND:
if (debug_mode)
break;
}
break;
#endif
}
if (clientSock != NULL) {
clientSock = NULL;
}
}
}
void AcceptUpdatedTest(void)
{
}
void AcceptNotUpdatedTest(void)
{
}
void AcceptReadTest(void)
{
}
void AcceptReadNotUpdatedTest(void)
{
}
void AcceptReadCallbackTest(void)
{
}
void TimeoutAcceptUpdatedTest(void)
{
}
void TimeoutAcceptNotUpdatedTest(void)
{
}
void TimeoutAcceptReadCallbackTest(void)
{
}
void TimeoutReadUpdatedTest(void)
{
}
void TimeoutReadNotUpdatedTest(void)
{
}
void TimeoutReadReadTest(void)
{
}
void TimeoutReadReadNotUpdatedTest(void)
{
}
void TimeoutReadReadCallbackTest(void)
{
}
/************************************************************************/
{
double d;
start = PR_IntervalNow();
(*func)();
stop = PR_IntervalNow();
if (debug_mode)
}
{
/* The command line argument: -d is used to determine if the test is being run
in debug mode. The regress tool requires only one line output:PASS or FAIL.
All of the printfs associated with this test has been handled with a if (debug_mode)
test.
Usage: test_name [-d] [-c n]
*/
{
if (PL_OPT_BAD == os) continue;
{
case 'G': /* global threads */
break;
case 'd': /* debug mode */
debug_mode = 1;
break;
case 'c': /* loop counter */
break;
default:
break;
}
}
#ifdef XP_MAC
SetupMacPrintfLog("accept.log");
debug_mode = 1;
#endif
if (debug_mode)
#ifdef WINNT
#endif
if (debug_mode)
#ifdef WINNT
#endif
if (debug_mode)
#ifdef WINNT
#endif
return failed_already;
}