#include "dgrambuf.h" #define _GNU_SOURCE #include #include #include #include #include int open_test_socket(); /* * Quick'n'dirty bash udp sender * while true; do echo $RANDOM > /dev/udp/127.0.0.1/1234; sleep 0.25; done */ int main() { int res, sockfd, info; dgrambuf_t dgb; sockfd = open_test_socket(); dgb = dgrambuf_new(3, 50, 8, 8); do { res = dgrambuf_recvmmsg(dgb, sockfd, 1, &info); printf("dgrambuf_recvmmsg() => %i\n", res); printf("dgrambuf_free_count => %zu\n", dgrambuf_get_free_count(dgb)); } while ( res > 0 ); return 0; } int open_test_socket() { int sockfd; struct sockaddr_in sa; sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) { perror("socket()"); exit(EXIT_FAILURE); } sa.sin_family = AF_INET; sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); sa.sin_port = htons(1234); if (bind(sockfd, (struct sockaddr *) &sa, sizeof(sa)) == -1) { perror("bind()"); exit(EXIT_FAILURE); } return sockfd; }