summaryrefslogtreecommitdiff
path: root/ctest.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-20 14:55:54 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-20 14:55:54 +0200
commit77f9be38d7469eefb0fac3adf43261b4d84315d2 (patch)
tree70c42ec4864e850e15b0c31b9493646ead42a05b /ctest.c
parente11014c0443ea687ad65a14b9124aa366da7984a (diff)
Make logging messages consistent in adding a newline for all messages
Diffstat (limited to 'ctest.c')
-rw-r--r--ctest.c74
1 files changed, 0 insertions, 74 deletions
diff --git a/ctest.c b/ctest.c
deleted file mode 100644
index b0a367d..0000000
--- a/ctest.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <string.h>
-#include <netinet/ip.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdbool.h>
-
-#define PIPE_RD 0
-#define PIPE_WR 1
-
-int
-main(int argc, char **argv) {
- int sfd;
- struct sockaddr_in addr;
- int zfd;
- int pfd[2];
- size_t total = 0;
-
- if (argc != 4) {
- fprintf(stderr, "Usage: %s <addr> <port> <64k count>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
-
- sfd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (sfd < 0) {
- perror("socket");
- exit(EXIT_FAILURE);
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(atoi(argv[2]));
- addr.sin_addr.s_addr = inet_addr(argv[1]);
-
- if (connect(sfd, &addr, sizeof(addr)) < 0) {
- perror("connect");
- exit(EXIT_FAILURE);
- }
-
- zfd = open("/dev/zero", O_RDONLY | O_CLOEXEC);
- if (zfd < 0) {
- perror("open");
- exit(EXIT_FAILURE);
- }
-
- if (pipe2(pfd, O_CLOEXEC) < 0) {
- perror("pipe2");
- exit(EXIT_FAILURE);
- }
-
- for (int i = 0; i < atoi(argv[3]); i++) {
- ssize_t r, w;
-
- r = splice(zfd, NULL, pfd[PIPE_WR], NULL, 64 * 1024, SPLICE_F_MOVE);
- //fprintf(stderr, "Read %zi bytes from /dev/zero\n", r);
- w = splice(pfd[PIPE_RD], NULL, sfd, NULL, r, SPLICE_F_MOVE);
- //fprintf(stderr, "Wrote %zi bytes to socket\n", w);
- if (r != w) {
- fprintf(stderr, "Read/write mismatch\n");
- exit(EXIT_FAILURE);
- }
- total += w;
- }
-
- printf("Client: sent %zu bytes\n", total);
- exit(EXIT_SUCCESS);
-}
-