summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/tests/nonblock.c
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
commitf7d30133221896638f7bf4f66c504255c4b14f48 (patch)
tree5f3e07a049f388a3a309a615b8884318f6668a98 /nsprpub/pr/tests/nonblock.c
parent26b297510a11758727438df4669357a2a2bc42ce (diff)
downloadUXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.gz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.lz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.xz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.zip
Issue #1338 - Part 1: Update NSPR to 4.24
Diffstat (limited to 'nsprpub/pr/tests/nonblock.c')
-rw-r--r--nsprpub/pr/tests/nonblock.c106
1 files changed, 52 insertions, 54 deletions
diff --git a/nsprpub/pr/tests/nonblock.c b/nsprpub/pr/tests/nonblock.c
index e94b1b44d..f24ffb02d 100644
--- a/nsprpub/pr/tests/nonblock.c
+++ b/nsprpub/pr/tests/nonblock.c
@@ -23,8 +23,6 @@
** Make win16 unit_time interval 300 milliseconds, others get 100
*/
#define UNIT_TIME 200 /* unit time in milliseconds */
-#elif defined(SYMBIAN)
-#define UNIT_TIME 5000 /* unit time in milliseconds */
#else
#define UNIT_TIME 100 /* unit time in milliseconds */
#endif
@@ -66,13 +64,13 @@ clientThreadFunc(void *arg)
retVal = PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
if (retVal == PR_FAILURE && PR_GetError() == PR_IN_PROGRESS_ERROR) {
#if !defined(USE_PR_SELECT)
- PRPollDesc pd;
- PRInt32 n;
- fprintf(stderr, "connect: EWOULDBLOCK, good\n");
- pd.fd = sock;
- pd.in_flags = PR_POLL_WRITE;
- n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(n == 1);
+ PRPollDesc pd;
+ PRInt32 n;
+ fprintf(stderr, "connect: EWOULDBLOCK, good\n");
+ pd.fd = sock;
+ pd.in_flags = PR_POLL_WRITE;
+ n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
+ PR_ASSERT(n == 1);
PR_ASSERT(pd.out_flags == PR_POLL_WRITE);
#else
PR_fd_set writeSet;
@@ -91,17 +89,17 @@ clientThreadFunc(void *arg)
/* time 4, 7, 11, etc. */
for (i = 0; i < NUMBER_ROUNDS; i++) {
PR_Sleep(3 * unitTime);
- nBytes = PR_Write(sock, buf, sizeof(buf));
- if (nBytes == -1) {
- if (PR_GetError() == PR_WOULD_BLOCK_ERROR) {
- fprintf(stderr, "write: EWOULDBLOCK\n");
- exit(1);
+ nBytes = PR_Write(sock, buf, sizeof(buf));
+ if (nBytes == -1) {
+ if (PR_GetError() == PR_WOULD_BLOCK_ERROR) {
+ fprintf(stderr, "write: EWOULDBLOCK\n");
+ exit(1);
} else {
- fprintf(stderr, "write: failed\n");
+ fprintf(stderr, "write: failed\n");
}
- }
- printf("client sent %d bytes\n", nBytes);
- fflush(stdout);
+ }
+ printf("client sent %d bytes\n", nBytes);
+ fflush(stdout);
}
PR_Close(sock);
@@ -121,38 +119,38 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
/* Create a listening socket */
if ((listenSock = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- exit(1);
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ exit(1);
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- exit(1);
+ fprintf(stderr, "Can't bind socket\n");
+ exit(1);
}
if (PR_GetSockName(listenSock, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- exit(1);
+ fprintf(stderr, "PR_GetSockName failed\n");
+ exit(1);
}
listenPort = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- exit(1);
+ fprintf(stderr, "Can't listen on a socket\n");
+ exit(1);
}
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on port %hu\n\n",
- listenPort);
+ "The server thread is listening on port %hu\n\n",
+ listenPort);
printf("%s", buf);
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- exit(1);
+ fprintf(stderr, "can't create thread\n");
+ exit(1);
}
printf("client thread created.\n");
@@ -165,7 +163,7 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
if (sock != NULL || PR_GetError() != PR_WOULD_BLOCK_ERROR) {
PL_PrintError("First Accept\n");
fprintf(stderr, "First PR_Accept() xxx\n" );
- exit(1);
+ exit(1);
}
printf("accept: EWOULDBLOCK, good\n");
fflush(stdout);
@@ -176,7 +174,7 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
PL_PrintError("Second Accept\n");
fprintf(stderr, "Second PR_Accept() failed: (%d, %d)\n",
PR_GetError(), PR_GetOSError());
- exit(1);
+ exit(1);
}
printf("accept: succeeded, good\n");
fflush(stdout);
@@ -186,26 +184,26 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
/* time 3, 5, 6, 8, etc. */
for (i = 0; i < NUMBER_ROUNDS; i++) {
- PR_Sleep(unitTime);
- retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
- if (retVal != -1 || PR_GetError() != PR_WOULD_BLOCK_ERROR) {
- PL_PrintError("First Receive:\n");
- fprintf(stderr, "First PR_Recv: retVal: %ld, Error: %ld\n",
- retVal, PR_GetError());
- exit(1);
+ PR_Sleep(unitTime);
+ retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
+ if (retVal != -1 || PR_GetError() != PR_WOULD_BLOCK_ERROR) {
+ PL_PrintError("First Receive:\n");
+ fprintf(stderr, "First PR_Recv: retVal: %ld, Error: %ld\n",
+ retVal, PR_GetError());
+ exit(1);
}
- printf("read: EWOULDBLOCK, good\n");
- fflush(stdout);
- PR_Sleep(2 * unitTime);
- retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
- if (retVal != CHUNK_SIZE) {
- PL_PrintError("Second Receive:\n");
- fprintf(stderr, "Second PR_Recv: retVal: %ld, Error: %ld\n",
- retVal, PR_GetError());
- exit(1);
+ printf("read: EWOULDBLOCK, good\n");
+ fflush(stdout);
+ PR_Sleep(2 * unitTime);
+ retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
+ if (retVal != CHUNK_SIZE) {
+ PL_PrintError("Second Receive:\n");
+ fprintf(stderr, "Second PR_Recv: retVal: %ld, Error: %ld\n",
+ retVal, PR_GetError());
+ exit(1);
}
- printf("read: %d bytes, good\n", retVal);
- fflush(stdout);
+ printf("read: %d bytes, good\n", retVal);
+ fflush(stdout);
}
PR_Close(sock);
@@ -217,7 +215,7 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
int main(int argc, char **argv)
{
PRIntn rv;
-
+
PR_STDIO_INIT();
rv = PR_Initialize(RealMain, argc, argv, 0);
return rv;