#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=1, sockfd=open_test_socket(); dgrambuf_t dgb=dgrambuf_new(3, 50); while (res > 0) { res = dgrambuf_recvmmsg(dgb, sockfd); printf("dgrambuf_recvmmsg() => %i\n", res); printf("dgrambuf_free_count => %zi\n", dgrambuf_free_count(dgb)); } 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; }