using explicit fflush instead of setvbuf (#133)
Because line-buffering doesn't exist on Windows ... Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
parent
959a096372
commit
c39cc74e13
6 changed files with 133 additions and 30 deletions
|
@ -31,6 +31,7 @@ int main (int argc, char ** argv)
|
|||
DDS_FATAL("dds_create_write: %s\n", dds_strretcode(-writer));
|
||||
|
||||
printf("=== [Publisher] Waiting for a reader to be discovered ...\n");
|
||||
fflush (stdout);
|
||||
|
||||
rc = dds_set_status_mask(writer, DDS_PUBLICATION_MATCHED_STATUS);
|
||||
if (rc != DDS_RETCODE_OK)
|
||||
|
@ -52,6 +53,7 @@ int main (int argc, char ** argv)
|
|||
|
||||
printf ("=== [Publisher] Writing : ");
|
||||
printf ("Message (%d, %s)\n", msg.userID, msg.message);
|
||||
fflush (stdout);
|
||||
|
||||
rc = dds_write (writer, &msg);
|
||||
if (rc != DDS_RETCODE_OK)
|
||||
|
|
|
@ -40,6 +40,7 @@ int main (int argc, char ** argv)
|
|||
dds_delete_qos(qos);
|
||||
|
||||
printf ("\n=== [Subscriber] Waiting for a sample ...\n");
|
||||
fflush (stdout);
|
||||
|
||||
/* Initialize sample buffer, by pointing the void pointer within
|
||||
* the buffer array to a valid sample memory location. */
|
||||
|
@ -61,6 +62,7 @@ int main (int argc, char ** argv)
|
|||
msg = (HelloWorldData_Msg*) samples[0];
|
||||
printf ("=== [Subscriber] Received : ");
|
||||
printf ("Message (%d, %s)\n", msg->userID, msg->message);
|
||||
fflush (stdout);
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -193,6 +193,7 @@ static void data_available(dds_entity_t rd, void *arg)
|
|||
readAccess.count,
|
||||
exampleGetMedianFromTimeStats (&readAccess),
|
||||
readAccess.min);
|
||||
fflush (stdout);
|
||||
|
||||
exampleResetTimeStats (&roundTrip);
|
||||
exampleResetTimeStats (&writeAccess);
|
||||
|
@ -282,11 +283,10 @@ int main (int argc, char *argv[])
|
|||
}
|
||||
prepare_dds(&writer, &reader, &readCond, listener);
|
||||
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
|
||||
if (argc - argidx == 1 && strcmp (argv[argidx], "quit") == 0)
|
||||
{
|
||||
printf ("Sending termination request.\n");
|
||||
fflush (stdout);
|
||||
/* pong uses a waitset which is triggered by instance disposal, and
|
||||
quits when it fires. */
|
||||
dds_sleepfor (DDS_SECS (1));
|
||||
|
@ -325,6 +325,7 @@ int main (int argc, char *argv[])
|
|||
if (invalidargs || (argc - argidx == 1 && (strcmp (argv[argidx], "-h") == 0 || strcmp (argv[argidx], "--help") == 0)))
|
||||
usage();
|
||||
printf ("# payloadSize: %" PRIu32 " | numSamples: %" PRIu64 " | timeOut: %" PRIi64 "\n\n", payloadSize, numSamples, timeOut);
|
||||
fflush (stdout);
|
||||
|
||||
pub_data.payload._length = payloadSize;
|
||||
pub_data.payload._buffer = payloadSize ? dds_alloc (payloadSize) : NULL;
|
||||
|
@ -337,6 +338,7 @@ int main (int argc, char *argv[])
|
|||
|
||||
startTime = dds_time ();
|
||||
printf ("# Waiting for startup jitter to stabilise\n");
|
||||
fflush (stdout);
|
||||
/* Write a sample that pong can send back */
|
||||
while (!dds_triggered (waitSet) && difference < DDS_SECS(5))
|
||||
{
|
||||
|
@ -358,11 +360,10 @@ int main (int argc, char *argv[])
|
|||
{
|
||||
warmUp = false;
|
||||
printf("# Warm up complete.\n\n");
|
||||
|
||||
printf("# Latency measurements (in us)\n");
|
||||
printf("# Latency [us] Write-access time [us] Read-access time [us]\n");
|
||||
printf("# Seconds Count median min 99%% max Count median min Count median min\n");
|
||||
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
exampleResetTimeStats (&roundTrip);
|
||||
|
@ -403,6 +404,7 @@ int main (int argc, char *argv[])
|
|||
exampleGetMedianFromTimeStats (&readAccessOverall),
|
||||
readAccessOverall.min
|
||||
);
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
done:
|
||||
|
|
|
@ -47,10 +47,6 @@ int main (int argc, char **argv)
|
|||
dds_return_t rc;
|
||||
ThroughputModule_DataType sample;
|
||||
|
||||
#if !defined(_WIN32)
|
||||
setvbuf (stdout, NULL, _IOLBF, 0);
|
||||
#endif
|
||||
|
||||
if (parse_args(argc, argv, &payloadSize, &burstInterval, &burstSize, &timeOut, &partitionName) == EXIT_FAILURE) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -60,6 +56,7 @@ int main (int argc, char **argv)
|
|||
/* Wait until have a reader */
|
||||
if (wait_for_reader(writer, participant) == 0) {
|
||||
printf ("=== [Publisher] Did not discover a reader.\n");
|
||||
fflush (stdout);
|
||||
rc = dds_delete (participant);
|
||||
if (rc < 0)
|
||||
DDS_FATAL("dds_delete: %s\n", dds_strretcode(-rc));
|
||||
|
@ -131,6 +128,7 @@ static int parse_args(
|
|||
|
||||
printf ("payloadSize: %u bytes burstInterval: %u ms burstSize: %u timeOut: %u seconds partitionName: %s\n",
|
||||
*payloadSize, *burstInterval, *burstSize, *timeOut, *partitionName);
|
||||
fflush (stdout);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -182,6 +180,7 @@ static dds_entity_t prepare_dds(dds_entity_t *writer, const char *partitionName)
|
|||
static dds_return_t wait_for_reader(dds_entity_t writer, dds_entity_t participant)
|
||||
{
|
||||
printf ("\n=== [Publisher] Waiting for a reader ...\n");
|
||||
fflush (stdout);
|
||||
|
||||
dds_return_t rc;
|
||||
dds_entity_t waitset;
|
||||
|
@ -224,6 +223,7 @@ static void start_writing(
|
|||
unsigned int burstCount = 0;
|
||||
|
||||
printf ("=== [Publisher] Writing samples...\n");
|
||||
fflush (stdout);
|
||||
|
||||
while (!done && !timedOut)
|
||||
{
|
||||
|
@ -277,14 +277,8 @@ static void start_writing(
|
|||
}
|
||||
dds_write_flush (writer);
|
||||
|
||||
if (done)
|
||||
{
|
||||
printf ("=== [Publisher] Terminated, %llu samples written.\n", (unsigned long long) sample->count);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("=== [Publisher] Timed out, %llu samples written.\n", (unsigned long long) sample->count);
|
||||
}
|
||||
printf ("=== [Publisher] %s, %llu samples written.\n", done ? "Terminated" : "Timed out", (unsigned long long) sample->count);
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,20 +75,18 @@ int main (int argc, char **argv)
|
|||
dds_entity_t participant;
|
||||
dds_entity_t reader;
|
||||
|
||||
#if !defined(_WIN32)
|
||||
setvbuf (stdout, NULL, _IOLBF, 0);
|
||||
#endif
|
||||
|
||||
if (parse_args(argc, argv, &maxCycles, &partitionName) == EXIT_FAILURE)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf ("Cycles: %llu | PollingDelay: %ld | Partition: %s\n", maxCycles, pollingDelay, partitionName);
|
||||
fflush (stdout);
|
||||
|
||||
participant = prepare_dds(&reader, partitionName);
|
||||
|
||||
printf ("=== [Subscriber] Waiting for samples...\n");
|
||||
fflush (stdout);
|
||||
|
||||
/* Process samples until Ctrl-C is pressed or until maxCycles */
|
||||
/* has been reached (0 = infinite) */
|
||||
|
@ -280,6 +278,7 @@ static void process_samples(dds_entity_t reader, unsigned long long maxCycles)
|
|||
deltaTime, payloadSize, total_samples, total_bytes, outOfOrder,
|
||||
(deltaTime != 0.0) ? ((double)(total_samples - prev_samples) / deltaTime) : 0,
|
||||
(deltaTime != 0.0) ? ((double)((total_bytes - prev_bytes) / BYTES_PER_SEC_TO_MEGABITS_PER_SEC) / deltaTime) : 0);
|
||||
fflush (stdout);
|
||||
cycles++;
|
||||
prev_time = time_now;
|
||||
prev_bytes = total_bytes;
|
||||
|
@ -300,6 +299,7 @@ static void process_samples(dds_entity_t reader, unsigned long long maxCycles)
|
|||
printf ("Out of order: %llu samples\n", outOfOrder);
|
||||
printf ("Average transfer rate: %.2lf samples/s, ", (double)total_samples / deltaTime);
|
||||
printf ("%.2lf Mbit/s\n", (double)(total_bytes / BYTES_PER_SEC_TO_MEGABITS_PER_SEC) / deltaTime);
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
static dds_entity_t prepare_dds(dds_entity_t *reader, const char *partitionName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue