Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Add recvmsg flags test
Browse files Browse the repository at this point in the history
  • Loading branch information
baluchicken committed Apr 25, 2024
1 parent 326223d commit 0b80d06
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
55 changes: 29 additions & 26 deletions test/recvflags.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <unistd.h>
#include <sys/stat.h>

int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions test/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0b80d06

Please sign in to comment.