17 #include <sys/types.h> 18 #include <sys/socket.h> 19 #include <netinet/in.h> 20 #include <arpa/inet.h> 24 #include <sys/ucontext.h> 41 for (i = 1; i < 32; i++)
43 memset (&sa, 0,
sizeof (sa));
45 sa.sa_flags = SA_SIGINFO;
60 sa.sa_sigaction = (
void *) SIG_IGN;
68 if (sigaction (i, &sa, 0) < 0)
75 main (
int argc,
char *argv[])
77 int sockfd, portno, n, sent, accfd, reuse;
78 socklen_t client_addr_len;
79 struct sockaddr_in serv_addr;
80 struct sockaddr_in client;
81 struct hostent *server;
82 u8 *rx_buffer = 0, no_echo = 0;
83 struct timeval start, end;
87 if (argc > 1 && argc < 3)
89 fformat (stderr,
"usage %s host port\n", argv[0]);
95 no_echo = atoi (argv[3]);
96 portno = atoi (argv[2]);
97 server = gethostbyname (argv[1]);
108 server = gethostbyname (
"6.0.1.1");
119 sockfd = socket (AF_INET, SOCK_STREAM, 0);
127 if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, (
const char *) &reuse,
134 bzero ((
char *) &serv_addr,
sizeof (serv_addr));
135 serv_addr.sin_family = AF_INET;
136 bcopy ((
char *) server->h_addr,
137 (
char *) &serv_addr.sin_addr.s_addr, server->h_length);
138 serv_addr.sin_port = htons (portno);
139 if (bind (sockfd, (
const void *) &serv_addr,
sizeof (serv_addr)) < 0)
147 if (listen (sockfd, 5 ) < 0)
159 client_addr_len =
sizeof (
struct sockaddr);
160 accfd = accept (sockfd, (
struct sockaddr *) &client, &client_addr_len);
166 fformat (stderr,
"Accepted connection from: %s : %d\n",
167 inet_ntoa (client.sin_addr), client.sin_port);
168 gettimeofday (&start, NULL);
172 n = recv (accfd, rx_buffer,
vec_len (rx_buffer), 0 );
177 gettimeofday (&end, NULL);
178 deltat = (end.tv_sec - start.tv_sec);
179 deltat += (end.tv_usec - start.tv_usec) / 1000000.0;
182 (((
f64) rcvd * 8.0) / deltat / 1e9),
183 no_echo ?
"half" :
"full");
201 sent = send (accfd, rx_buffer, n, 0 );
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static void setup_signal_handler(void)
int main(int argc, char *argv[])
#define clib_unix_error(format, args...)
volatile int signal_received
#define clib_warning(format, args...)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define clib_unix_warning(format, args...)
static void unix_signal_handler(int signum, siginfo_t *si, ucontext_t *uc)