prpoll.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 ***** */
#ifdef WIN32
#include <windows.h>
#endif
#ifdef XP_OS2_VACPP
#include <io.h> /* for close() */
#endif
#include "prinit.h"
#include "prio.h"
#include "prlog.h"
#include "prprf.h"
#include "prnetdb.h"
#ifndef XP_MAC
#else
#include "pprio.h"
#endif
#define CLIENT_LOOPS 5
#define BUF_SIZE 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static void
clientThreadFunc(void *arg)
{
int i;
for (i = 0; i < 5; i++) {
sock = PR_NewTCPSocket();
}
}
{
struct sockaddr_in saddr;
PRIntn i, j;
printf("This program tests PR_Poll with sockets.\n");
printf("Timeout, error reporting, and normal operation are tested.\n\n");
/* Create two listening sockets */
exit(1);
}
exit(1);
}
exit(1);
}
exit(1);
}
exit(1);
}
exit(1);
}
exit(1);
}
exit(1);
}
/* Set up the poll descriptor array */
npds = 0;
npds++;
npds++;
npds++;
"The server thread is listening on ports %hu, %hu and %hu\n\n",
/* Testing timeout */
printf("PR_Poll should time out in 5 seconds\n");
if (retVal != 0) {
"PR_Poll should time out and return 0, but it returns %ld\n",
retVal);
exit(1);
}
printf("PR_Poll timed out. Test passed.\n\n");
/* Testing bad fd */
printf("PR_Poll should detect a bad file descriptor\n");
exit(1);
}
npds++;
#if 0
"PR_Poll returns %d, out_flags is 0x%hx\n",
exit(1);
}
printf("PR_Poll detected the bad fd. Test passed.\n\n");
#endif
npds--;
clientThreadFunc, (void *) listenPort1,
PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
exit(1);
}
clientThreadFunc, (void *) listenPort2,
PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
exit(1);
}
clientThreadFunc, (void *) listenPort3,
PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
exit(1);
}
printf("Three client threads are created. Each of them will\n");
printf("send data to one of the three ports the server is listening on.\n");
printf("The data they send is the port number. Each of them send\n");
printf("the data five times, so you should see ten lines below,\n");
printf("interleaved in an arbitrary order.\n");
/* 30 events total */
i = 0;
while (i < 30) {
int nextIndex;
int nEvents = 0;
if (retVal == -1) {
exit(1);
}
nextIndex = 3;
/* the three listening sockets */
for (j = 0; j < 3; j++) {
nEvents++;
if (j == 2) {
int newsd;
if (newsd == -1) {
exit(1);
}
} else {
exit(1);
}
}
nextIndex++;
exit(1);
exit(1);
}
}
for (j = 3; j < npds; j++) {
nEvents++;
/* XXX: This call is a hack and should be fixed */
sizeof(buf), 0);
if (nBytes == -1) {
exit(1);
}
#ifdef WIN32
#else
#endif
} else {
if (nBytes == -1) {
exit(1);
}
}
/* Just to be safe */
exit(1);
exit(1);
} else {
nextIndex++;
}
}
/* swap */
i += nEvents;
}
printf("All tests finished\n");
PR_Cleanup();
return 0;
}