16 #ifndef __sock_test_h__ 17 #define __sock_test_h__ 25 #define SOCK_TEST_AF_UNIX_FILENAME "/tmp/ldp_server_af_unix_socket" 26 #define SOCK_TEST_MIXED_EPOLL_DATA "Hello, world! (over an AF_UNIX socket)" 27 #define SOCK_TEST_AF_UNIX_ACCEPT_DATA 0xaf0000af 28 #define SOCK_TEST_AF_UNIX_FD_MASK 0x00af0000 29 #define SOCK_TEST_BANNER_STRING \ 30 "============================================\n" 36 int rx_bytes, errno_val;
42 rx_bytes = read (fd, buf, nbytes);
45 if ((rx_bytes == 0) ||
46 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
48 else if (rx_bytes < nbytes)
52 while ((rx_bytes == 0) ||
53 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
58 perror (
"ERROR in sock_test_read()");
59 fprintf (stderr,
"SOCK_TEST: ERROR: socket read " 60 "failed (errno = %d)!\n", errno_val);
74 int nbytes_left = nbytes;
81 rv = write (fd, buf, nbytes_left);
84 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
95 if (tx_bytes != nbytes)
97 nbytes_left = nbytes_left - rv;
102 printf (
"SOCK_TEST: WARNING: bytes written (%d) " 103 "!= bytes to write (%d)!\n", tx_bytes, nbytes);
107 }
while (tx_bytes != nbytes);
112 perror (
"ERROR in sock_test_write()");
113 fprintf (stderr,
"SOCK_TEST: ERROR: socket write failed " 114 "(errno = %d)!\n", errno_val);
static int sock_test_read(int fd, uint8_t *buf, uint32_t nbytes, vcl_test_stats_t *stats)
Optimized string handling code, including c11-compliant "safe C library" variants.
static int sock_test_write(int fd, uint8_t *buf, uint32_t nbytes, vcl_test_stats_t *stats, uint32_t verbose)