diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-20 14:55:54 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-20 14:55:54 +0200 |
commit | 77f9be38d7469eefb0fac3adf43261b4d84315d2 (patch) | |
tree | 70c42ec4864e850e15b0c31b9493646ead42a05b /stest.c | |
parent | e11014c0443ea687ad65a14b9124aa366da7984a (diff) |
Make logging messages consistent in adding a newline for all messages
Diffstat (limited to 'stest.c')
-rw-r--r-- | stest.c | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/stest.c b/stest.c deleted file mode 100644 index 94b5264..0000000 --- a/stest.c +++ /dev/null @@ -1,102 +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; - socklen_t addrsz = sizeof(addr); - int pfd[2]; - int r; - int cfd; - int zfd; - size_t total = 0; - - if (argc != 3) { - fprintf(stderr, "Usage: %s <addr> <port>\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]); - - int enable = 1; - if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) { - perror("setsockopt"); - exit(EXIT_FAILURE); - } - - r = bind(sfd, (struct sockaddr *)&addr, sizeof(addr)); - if (r < 0) { - perror("bind"); - exit(EXIT_FAILURE); - } - - r = listen(sfd, 100); - if (r < 0) { - perror("listen"); - exit(EXIT_FAILURE); - } - - cfd = accept4(sfd, (struct sockaddr *)&addr, &addrsz, SOCK_CLOEXEC); - if (cfd < 0) { - perror("accept"); - exit(EXIT_FAILURE); - } - - zfd = open("/dev/null", O_WRONLY | O_CLOEXEC); - if (zfd < 0) { - perror("open"); - exit(EXIT_FAILURE); - } - - if (pipe2(pfd, O_CLOEXEC) < 0) { - perror("pipe2"); - exit(EXIT_FAILURE); - } - - while (true) { - ssize_t r, w; - - r = splice(cfd, NULL, pfd[PIPE_WR], NULL, 64 * 1024, SPLICE_F_MOVE); - if (r < 0) - perror("splice"); - //fprintf(stderr, "Read %zi bytes from socket\n", r); - if (r == 0) - break; - w = splice(pfd[PIPE_RD], NULL, zfd, NULL, r, SPLICE_F_MOVE); - if (w < 0) - perror("splice"); - if (w != r) { - fprintf(stderr, "Losing bytes\n"); - exit(EXIT_FAILURE); - } - //fprintf(stderr, "Wrote %zi bytes to /dev/null\n", r); - - total += w; - } - - printf("Server: received %zu bytes\n", total); -} - |