1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

fixed EOF handling in send tool and msg_fscan() function

This commit is contained in:
Steffen Vogel 2015-09-22 16:15:30 +02:00
parent 52b729cd79
commit cbf2276a8e
3 changed files with 14 additions and 18 deletions

View file

@ -65,12 +65,8 @@ int msg_fscan(FILE *f, struct msg *m)
char line[MSG_VALUES * 16];
char *next, *ptr = line;
retry: if (fgets(line, sizeof(line), f) == NULL) {
if (feof(f))
goto retry;
else
return -1; /* An error occured */
}
if (fgets(line, sizeof(line), f) == NULL)
return -1; /* An error occured */
m->ts.sec = (uint32_t) strtoul(ptr, &ptr, 10); ptr++;
m->ts.nsec = (uint32_t) strtoul(ptr, &ptr, 10);

View file

@ -21,7 +21,7 @@
int main(int argc, char *argv[])
{
if (argc <= 3 || argc > 4) {
if (argc < 3 || argc > 4) {
printf("Usage: %s VALUES RATE [LIMIT]\n", argv[0]);
printf(" VALUES is the number of values a message contains\n");
printf(" RATE how many messages per second\n");
@ -35,9 +35,9 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
int limit = argc >= 4 ? atoi(argv[3]) : 0;
double rate = strtod(argv[2], NULL);
struct msg m = MSG_INIT(atoi(argv[1]));
double rate = atof(argv[2]);
int limit = argc >= 4 ? atoi(argv[3]) : -1;
/* Setup timer */
struct itimerspec its = {
@ -56,7 +56,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "# %-20s\t%s\t%s\n", "timestamp", "seqno", "data[]");
/* Block until 1/p->rate seconds elapsed */
for (;;) {
while (limit-- > 0 || argc < 4) {
m.sequence += timerfd_wait(tfd);
struct timespec ts;
@ -69,9 +69,6 @@ int main(int argc, char *argv[])
msg_fprint(stdout, &m);
fflush(stdout);
if (limit && --limit == 0)
break;
}
close(tfd);

View file

@ -113,16 +113,19 @@ int main(int argc, char *argv[])
/* Print header */
fprintf(stderr, "# %-20s\t%s\t%s\n", "timestamp", "seqno", "data[]");
while (!feof(stdin)) {
for (int i = 0; i < node->combine; i++) {
msg_fscan(stdin, &pool[i]);
msg_fprint(stdout, &pool[i]);
for (;;) {
int i = 0;
while (i < node->combine) {
if (msg_fscan(stdin, &pool[i]) > 0)
msg_fprint(stdout, &pool[i++]);
else if (feof(stdin))
goto out;
}
node_write(node, pool, node->combine, 0, node->combine);
}
quit();
out: quit();
return 0;
}