From 0b80d06373d2cddf5bd89714804edb0a027eef35 Mon Sep 17 00:00:00 2001 From: Balint Molnar Date: Thu, 25 Apr 2024 15:25:35 +0200 Subject: [PATCH] Add recvmsg flags test --- test/recvflags.c | 55 +++++++++++++++++++++++++----------------------- test/smoke.sh | 4 ++++ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/test/recvflags.c b/test/recvflags.c index a5e29848..c60b4eb7 100644 --- a/test/recvflags.c +++ b/test/recvflags.c @@ -15,6 +15,7 @@ #include #include #include +#include int main(int argc, char *argv[]) { @@ -43,50 +44,52 @@ int main(int argc, char *argv[]) goto error; } - printf("Msg: %s was sent\n", msg); + struct stat st; + if (stat("README.md", &st) < 0) + { + perror("could not determine file size"); + goto error; + } + + typedef enum + { + WAITALL_AND_TRUNCATE, + WAITALL, + NONE + } RecvFlags; int n = 0; - int i = 0; - int flags = MSG_TRUNC; - while (n != 8785) + RecvFlags flag_state = WAITALL_AND_TRUNCATE; + int flags = 0; + while (n != st.st_size + 190) { char buf[4096] = {0}; int recv_size; - if (i == 0) + + switch (flag_state) { + case WAITALL_AND_TRUNCATE: + flags = MSG_TRUNC; flags |= MSG_WAITALL; - } - else if (i == 1) - { + flag_state = WAITALL; + break; + case WAITALL: flags = MSG_WAITALL; - } - else - { + flag_state = NONE; + break; + case NONE: flags = 0; + break; } + if ((recv_size = recv(sock, buf, sizeof(buf), flags)) < 0) { perror("something went wrong during recv"); goto error; } n += recv_size; - printf("!!!!!!!!!!!!!!!!!!!!!!%d", n); - printf("%.*s", n, buf); - i++; } - printf("\n%d amount of bytes were received\n", n); - - // int i = 0; - // char buf[4096] = {0}; - // if ((i = recv(sock, buf, sizeof(buf), 0)) < 0) - // { - // perror("something happened during recv"); - // goto error; - // } - // printf("%.*s", i, buf); - // printf("\n%d amount of bytes were received\n", i); - close(sock); return 0; diff --git a/test/smoke.sh b/test/smoke.sh index 43d67395..9de26367 100755 --- a/test/smoke.sh +++ b/test/smoke.sh @@ -78,3 +78,7 @@ gcc -o sockopt test/sockopt.c echo "Test passthrough ALPN on file-server with TLS" python3 test/passthrough.py + +echo "Test various recv flag parameters" +gcc -o flags test/recvflags.c +./flags \ No newline at end of file