summaryrefslogtreecommitdiff
path: root/pr/tests/nonblock.c
diff options
context:
space:
mode:
Diffstat (limited to 'pr/tests/nonblock.c')
-rw-r--r--pr/tests/nonblock.c102
1 files changed, 51 insertions, 51 deletions
diff --git a/pr/tests/nonblock.c b/pr/tests/nonblock.c
index e9d19d18..f24ffb02 100644
--- a/pr/tests/nonblock.c
+++ b/pr/tests/nonblock.c
@@ -64,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;
@@ -89,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);
@@ -119,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");
@@ -163,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);
@@ -174,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);
@@ -184,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);