diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2020-08-14 16:10:21 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2020-08-14 16:10:21 +0200 |
commit | a5f8783bda10fe444bd70f61e404a21b226d82f7 (patch) | |
tree | 9d3e14065c911db26504f5f6c7e30bd2f66dd33e | |
parent | 37e46a506ace9f010601a0429685c9c5eb4408b6 (diff) |
minor improvments
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | examples/c-json-stdout/c-json-stdout.c | 11 | ||||
-rw-r--r-- | nDPIsrvd.c | 6 |
2 files changed, 10 insertions, 7 deletions
diff --git a/examples/c-json-stdout/c-json-stdout.c b/examples/c-json-stdout/c-json-stdout.c index c6594588b..183d072ee 100644 --- a/examples/c-json-stdout/c-json-stdout.c +++ b/examples/c-json-stdout/c-json-stdout.c @@ -56,6 +56,7 @@ int main(void) if (bytes_read <= 0 || errno != 0) { + fprintf(stderr, "Remote end disconnected.\n"); break; } @@ -64,7 +65,7 @@ int main(void) { if (buf[nDPIsrvd_JSON_BYTES] != '{') { - fprintf(stderr, "BUG: JSON invalid opening character: '%c'", buf[nDPIsrvd_JSON_BYTES]); + fprintf(stderr, "BUG: JSON invalid opening character: '%c'\n", buf[nDPIsrvd_JSON_BYTES]); exit(1); } @@ -75,17 +76,17 @@ int main(void) if (errno == ERANGE) { - fprintf(stderr, "BUG: Size of JSON exceeds limit"); + fprintf(stderr, "BUG: Size of JSON exceeds limit\n"); exit(1); } if ((uint8_t *)json_str_start == buf) { - fprintf(stderr, "BUG: Missing size before JSON string: \"%.*s\"", nDPIsrvd_JSON_BYTES, buf); + fprintf(stderr, "BUG: Missing size before JSON string: \"%.*s\"\n", nDPIsrvd_JSON_BYTES, buf); exit(1); } if (json_bytes > sizeof(buf)) { - fprintf(stderr, "BUG: JSON string too big: %llu > %zu", json_bytes, sizeof(buf)); + fprintf(stderr, "BUG: JSON string too big: %llu > %zu\n", json_bytes, sizeof(buf)); exit(1); } if (json_bytes > buf_used) @@ -95,7 +96,7 @@ int main(void) if (buf[json_bytes - 1] != '}') { - fprintf(stderr, "BUG: Invalid JSON string: %.*s", (int)json_bytes, buf); + fprintf(stderr, "BUG: Invalid JSON string: %.*s\n", (int)json_bytes, buf); exit(1); } diff --git a/nDPIsrvd.c b/nDPIsrvd.c index f1c450443..a8fa2499d 100644 --- a/nDPIsrvd.c +++ b/nDPIsrvd.c @@ -384,7 +384,7 @@ int main(int argc, char ** argv) { shutdown(current->fd, SHUT_WR); // collector } else { - shutdown(current->fd, SHUT_RD); // descriptor + shutdown(current->fd, SHUT_RD); // distributor } /* setup epoll event */ @@ -422,6 +422,9 @@ int main(int argc, char ** argv) errno = 0; ssize_t bytes_read = read(current->fd, current->buf.ptr + current->buf.used, current->buf.max - current->buf.used); + if (errno == EAGAIN) { + continue; + } if (bytes_read < 0 || errno != 0) { disconnect_client(epollfd, current); @@ -435,7 +438,6 @@ int main(int argc, char ** argv) disconnect_client(epollfd, current); continue; } - current->buf.used += bytes_read; while (current->event_json.json_bytes == 0 && current->buf.used >= nDPIsrvd_JSON_BYTES + 1) |