summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%netscape.com <devnull@localhost>1999-02-12 18:41:52 +0000
committerwtc%netscape.com <devnull@localhost>1999-02-12 18:41:52 +0000
commit1bffb4673d58893e795a1cfbb5977d43f040802f (patch)
tree79b27438de9d56c73b34b949c4a0a9548e46f409
parentbe33bc6f908bb8dc03e1aa8907188d41c02458b7 (diff)
downloadnspr-hg-1bffb4673d58893e795a1cfbb5977d43f040802f.tar.gz
Minor improvements.
-rw-r--r--pr/tests/pipeping.c20
-rw-r--r--pr/tests/pipepong.c17
-rw-r--r--pr/tests/sockping.c20
-rw-r--r--pr/tests/sockpong.c17
4 files changed, 47 insertions, 27 deletions
diff --git a/pr/tests/pipeping.c b/pr/tests/pipeping.c
index c2eedec2..1766cffe 100644
--- a/pr/tests/pipeping.c
+++ b/pr/tests/pipeping.c
@@ -31,9 +31,12 @@
* inheritance, standard I/O redirection.
*/
-#include "nspr.h"
+#include "prerror.h"
+#include "prio.h"
+#include "prproces.h"
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
static char *child_argv[] = { "pipepong", NULL };
@@ -102,21 +105,28 @@ int main()
for (idx = 0; idx < NUM_ITERATIONS; idx++) {
strcpy(buf, "ping");
- printf("pipeping: sending \"%s\"\n", buf);
+ printf("ping process: sending \"%s\"\n", buf);
nBytes = PR_Write(out_pipe[1], buf, 5);
if (nBytes == -1) {
fprintf(stderr, "PR_Write failed: (%d, %d)\n", PR_GetError(),
PR_GetOSError());
exit(1);
}
+ memset(buf, 0, sizeof(buf));
nBytes = PR_Read(in_pipe[0], buf, sizeof(buf));
if (nBytes == -1) {
- fprintf(stderr, "PR_Read failed\n");
+ fprintf(stderr, "PR_Read failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ exit(1);
+ }
+ printf("ping process: received \"%s\"\n", buf);
+ if (nBytes != 5) {
+ fprintf(stderr, "ping process: expected 5 bytes but got %d bytes\n",
+ nBytes);
exit(1);
}
- printf("pipeping: received \"%s\"\n", buf);
if (strcmp(buf, "pong") != 0) {
- fprintf(stderr, "pipeping: expected \"pong\" but got \"%s\"\n",
+ fprintf(stderr, "ping process: expected \"pong\" but got \"%s\"\n",
buf);
exit(1);
}
diff --git a/pr/tests/pipepong.c b/pr/tests/pipepong.c
index d0664542..9ac62a5e 100644
--- a/pr/tests/pipepong.c
+++ b/pr/tests/pipepong.c
@@ -44,25 +44,28 @@ int main()
size_t nBytes;
int idx;
- memset(buf, 0, sizeof(buf));
-
for (idx = 0; idx < NUM_ITERATIONS; idx++) {
+ memset(buf, 0, sizeof(buf));
nBytes = fread(buf, 1, 5, stdin);
- fprintf(stderr, "pipepong: received \"%s\"\n", buf);
+ fprintf(stderr, "pong process: received \"%s\"\n", buf);
if (nBytes != 5) {
- fprintf(stderr, "pipepong: expected 5 bytes but got %d bytes\n",
+ fprintf(stderr, "pong process: expected 5 bytes but got %d bytes\n",
nBytes);
exit(1);
}
if (strcmp(buf, "ping") != 0) {
- fprintf(stderr, "pipepong: expected \"ping\" but got \"%s\"\n",
+ fprintf(stderr, "pong process: expected \"ping\" but got \"%s\"\n",
buf);
exit(1);
}
strcpy(buf, "pong");
- fprintf(stderr, "pipepong: sending \"%s\"\n", buf);
- printf("%s", buf);
+ fprintf(stderr, "pong process: sending \"%s\"\n", buf);
+ nBytes = fwrite(buf, 1, 5, stdout);
+ if (nBytes != 5) {
+ fprintf(stderr, "pong process: fwrite failed\n");
+ exit(1);
+ }
fflush(stdout);
}
diff --git a/pr/tests/sockping.c b/pr/tests/sockping.c
index cc31b5c6..43c97b7a 100644
--- a/pr/tests/sockping.c
+++ b/pr/tests/sockping.c
@@ -30,6 +30,7 @@
* descriptor inheritance.
*/
+#include "prerror.h"
#include "prio.h"
#include "prproces.h"
@@ -60,7 +61,8 @@ int main()
status = PR_SetFDInheritable(sock[1], PR_TRUE);
if (status == PR_FAILURE) {
- fprintf(stderr, "PR_SetFDInheritable failed\n");
+ fprintf(stderr, "PR_SetFDInheritable failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
exit(1);
}
@@ -90,25 +92,27 @@ int main()
for (idx = 0; idx < NUM_ITERATIONS; idx++) {
strcpy(buf, "ping");
- printf("sockping: sending \"%s\"\n", buf);
+ printf("ping process: sending \"%s\"\n", buf);
nBytes = PR_Write(sock[0], buf, 5);
if (nBytes == -1) {
- fprintf(stderr, "PR_Write failed\n");
+ fprintf(stderr, "PR_Write failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
exit(1);
}
- nBytes = PR_Recv(sock[0], buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
+ memset(buf, 0, sizeof(buf));
+ nBytes = PR_Read(sock[0], buf, sizeof(buf));
if (nBytes == -1) {
- fprintf(stderr, "PR_Recv failed\n");
+ fprintf(stderr, "PR_Read failed\n");
exit(1);
}
+ printf("ping process: received \"%s\"\n", buf);
if (nBytes != 5) {
- fprintf(stderr, "sockping: expected 5 bytes but got %d bytes\n",
+ fprintf(stderr, "ping process: expected 5 bytes but got %d bytes\n",
nBytes);
exit(1);
}
- printf("sockping: received \"%s\"\n", buf);
if (strcmp(buf, "pong") != 0) {
- fprintf(stderr, "sockping: expected \"pong\" but got \"%s\"\n",
+ fprintf(stderr, "ping process: expected \"pong\" but got \"%s\"\n",
buf);
exit(1);
}
diff --git a/pr/tests/sockpong.c b/pr/tests/sockpong.c
index 65aa20d1..503e6d65 100644
--- a/pr/tests/sockpong.c
+++ b/pr/tests/sockpong.c
@@ -30,6 +30,7 @@
* descriptor inheritance.
*/
+#include "prerror.h"
#include "prio.h"
#include <stdio.h>
@@ -58,28 +59,30 @@ int main()
}
for (idx = 0; idx < NUM_ITERATIONS; idx++) {
+ memset(buf, 0, sizeof(buf));
nBytes = PR_Read(sock, buf, sizeof(buf));
if (nBytes == -1) {
- fprintf(stderr, "PR_Read failed\n");
+ fprintf(stderr, "PR_Read failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
exit(1);
}
+ printf("pong process: received \"%s\"\n", buf);
if (nBytes != 5) {
- fprintf(stderr, "sockpong: expected 5 bytes but got %d bytes\n",
+ fprintf(stderr, "pong process: expected 5 bytes but got %d bytes\n",
nBytes);
exit(1);
}
- printf("sockpong: received \"%s\"\n", buf);
if (strcmp(buf, "ping") != 0) {
- fprintf(stderr, "sockpong: expected \"ping\" but got \"%s\"\n",
+ fprintf(stderr, "pong process: expected \"ping\" but got \"%s\"\n",
buf);
exit(1);
}
strcpy(buf, "pong");
- printf("sockpong: sending \"%s\"\n", buf);
- nBytes = PR_Send(sock, buf, 5, 0, PR_INTERVAL_NO_TIMEOUT);
+ printf("pong process: sending \"%s\"\n", buf);
+ nBytes = PR_Write(sock, buf, 5);
if (nBytes == -1) {
- fprintf(stderr, "PR_Send failed\n");
+ fprintf(stderr, "PR_Write failed\n");
exit(1);
}
}