1.1 --- a/tests/dstest_pipe_client.cc Fri Jul 02 23:53:13 2021 +0200
1.2 +++ b/tests/dstest_pipe_client.cc Tue Jul 06 00:45:25 2021 +0200
1.3 @@ -41,10 +41,19 @@
1.4
1.5 /* Use the writer to fill the pipe with data. */
1.6
1.7 -static void write_pipe(file_t *writer)
1.8 +static void write_pipe(file_t *writer, int number)
1.9 {
1.10 offset_t size = 600;
1.11 char buffer[size];
1.12 + long err;
1.13 +
1.14 + /* Make writers blocking to permit synchronisation. */
1.15 +
1.16 + if ((err = client_set_blocking(writer, NOTIFY_SPACE_AVAILABLE)))
1.17 + {
1.18 + printf("Could not set pipe #%d as blocking: %s\n", number, l4sys_errtostr(err));
1.19 + return;
1.20 + }
1.21
1.22 for (int loop = 0; loop < 3; loop++)
1.23 {
1.24 @@ -54,7 +63,7 @@
1.25
1.26 offset_t nwritten = client_write(writer, buffer, size);
1.27
1.28 - printf("Written %ld/%ld in #%d of %d/%d to pipe...\n", nwritten, size, region, loop, 2);
1.29 + printf("Written %ld/%ld in #%d of %d/%d to pipe #%d...\n", nwritten, size, region, loop, 2, number);
1.30 }
1.31
1.32 sleep(1);
1.33 @@ -74,23 +83,28 @@
1.34 offset_t size = 600, totals[] = {0, 0};
1.35 bool active[] = {true, true};
1.36 int num_active = 2;
1.37 - char buffer[size];
1.38 - offset_t nread;
1.39 + long err;
1.40 file_t *reader;
1.41 - long err;
1.42 +
1.43 + /* Register the readers for notification. */
1.44 +
1.45 + // NOTE: Use the flags to detect initial conditions!
1.46
1.47 - if ((err = client_wait_init(reader1)) || (err = client_wait_init(reader2)))
1.48 + if ((err = client_subscribe(reader1, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED)) ||
1.49 + (err = client_subscribe(reader2, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED)))
1.50 {
1.51 - printf("Could not initialise waiting for files: %s\n", l4sys_errtostr(err));
1.52 + printf("Could not subscribe to notifications: %s\n", l4sys_errtostr(err));
1.53 return;
1.54 }
1.55
1.56 while (1)
1.57 {
1.58 + char buffer[size];
1.59 + offset_t nread;
1.60 +
1.61 /* Wait for notification of content. */
1.62
1.63 - printf("Waiting...\n");
1.64 - long err = client_wait_files(&reader);
1.65 + err = client_wait_files(&reader);
1.66
1.67 if (err)
1.68 {
1.69 @@ -122,11 +136,11 @@
1.70 }
1.71 }
1.72
1.73 - do
1.74 + while (nread)
1.75 {
1.76 totals[p] += nread;
1.77
1.78 - printf("Read %ld/%ld, total %ld, from pipe #%d...\n", nread, size, totals[p], p + 1);
1.79 + printf("Read %ld/%ld, total %ld, first %c, last %c, from pipe #%d...\n", nread, size, totals[p], *buffer, *(buffer + nread - 1), p + 1);
1.80 #if 0
1.81 for (offset_t i = 0; i < nread; i += 60)
1.82 {
1.83 @@ -136,7 +150,6 @@
1.84 #endif
1.85 nread = client_read(reader, buffer, size);
1.86 }
1.87 - while (nread);
1.88 }
1.89
1.90 printf("Data shown.\n");
1.91 @@ -160,31 +173,13 @@
1.92 return 1;
1.93 }
1.94
1.95 - /* Register the readers for notification. */
1.96 -
1.97 - if ((err = client_subscribe(&reader1, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED)) ||
1.98 - (err = client_subscribe(&reader2, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED)))
1.99 - {
1.100 - printf("Could not subscribe to notifications: %s\n", l4sys_errtostr(err));
1.101 - return 1;
1.102 - }
1.103 -
1.104 - /* Make the writers blocking to permit synchronisation. */
1.105 -
1.106 - if ((err = client_set_blocking(&writer1, NOTIFY_SPACE_AVAILABLE)) ||
1.107 - (err = client_set_blocking(&writer2, NOTIFY_SPACE_AVAILABLE)))
1.108 - {
1.109 - printf("Could not set as blocking: %s\n", l4sys_errtostr(err));
1.110 - return 1;
1.111 - }
1.112 -
1.113 /* Schedule reader and writer threads. */
1.114
1.115 std::thread *activities[3];
1.116
1.117 activities[0] = new std::thread(read_pipes, &reader1, &reader2);
1.118 - activities[1] = new std::thread(write_pipe, &writer1);
1.119 - activities[2] = new std::thread(write_pipe, &writer2);
1.120 + activities[1] = new std::thread(write_pipe, &writer1, 1);
1.121 + activities[2] = new std::thread(write_pipe, &writer2, 2);
1.122
1.123 for (int i = 0; i < 3; i++)
1.124 activities[i]->join();