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"
32 #define stinf(_fmt, _args...) \
33 printf ("st: " _fmt "\n", ##_args)
34 #define stwrn(_fmt, _args...) \
35 printf ("WARNING: " _fmt "\n", ##_args)
36 #define sterr(_fn, _rv) \
39 printf ("\nERROR: " _fn " failed (errno = %d)!\n", -_rv); \
41 #define stabrt(_fmt, _args...) \
43 printf ("\nERROR: " _fmt "\n", ##_args); \
48 perror ("ERROR when calling " _fn); \
49 printf ("\nERROR: " _fn " failed (errno = %d)!\n", errno); \
63 rx_bytes = read (fd,
buf, nbytes);
66 if ((rx_bytes == 0) ||
68 && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
70 else if (rx_bytes < nbytes)
74 while ((rx_bytes == 0) ||
75 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
78 stfail (
"sock_test_read()");
81 stats->rx_bytes += rx_bytes;
90 int tx_bytes = 0, nbytes_left = nbytes,
rv;
96 rv = write (fd,
buf, nbytes_left);
99 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
110 if (tx_bytes != nbytes)
112 nbytes_left = nbytes_left -
rv;
117 stinf (
"bytes written (%d) != bytes to write (%d)!\n", tx_bytes,
123 while (tx_bytes != nbytes);
126 stfail (
"sock_test_write()");
129 stats->tx_bytes += tx_bytes;