2 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 #include <sys/types.h>
19 #include <sys/socket.h>
24 #include <hs_apps/vcl/sock_test.h>
27 #include <sys/ioctl.h>
29 #define SOCK_SERVER_USE_EPOLL 1
30 #define VPPCOM_SESSION_ATTR_UNIT_TEST 0
32 #if SOCK_SERVER_USE_EPOLL
33 #include <sys/epoll.h>
34 #if !defined(VCL_TEST)
40 #if VPPCOM_SESSION_ATTR_UNIT_TEST
41 #define BUFLEN sizeof (uint64_t) * 16
43 uint32_t buflen = BUFLEN;
44 uint32_t *flags = (uint32_t *) buffer;
55 vcl_test_stats_t stats;
66 uint32_t transport_udp;
69 #define SOCK_SERVER_MAX_TEST_CONN 10
70 #define SOCK_SERVER_MAX_EPOLL_EVENTS 10
74 sock_server_cfg_t cfg;
75 #if SOCK_SERVER_USE_EPOLL
77 struct epoll_event listen_ev;
78 struct epoll_event wait_events[SOCK_SERVER_MAX_EPOLL_EVENTS];
79 #if !defined (VCL_TEST)
80 int af_unix_listen_fd;
82 struct epoll_event af_unix_listen_ev;
83 struct sockaddr_un serveraddr;
84 uint32_t af_unix_xacts;
88 size_t conn_pool_size;
89 sock_server_conn_t *conn_pool;
93 struct timeval timeout;
96 sock_server_main_t sock_server_main;
98 #if ! SOCK_SERVER_USE_EPOLL
102 sock_server_main_t *ssm = &sock_server_main;
105 for (nfds = i = 0; i < FD_SETSIZE; i++)
107 if (FD_ISSET (i, &ssm->rd_fdset) || FD_ISSET (i, &ssm->wr_fdset))
114 conn_fdset_set (sock_server_conn_t * conn, fd_set * fdset)
116 sock_server_main_t *ssm = &sock_server_main;
118 FD_SET (conn->fd, fdset);
119 ssm->nfds = get_nfds ();
123 conn_fdset_clr (sock_server_conn_t * conn, fd_set * fdset)
125 sock_server_main_t *ssm = &sock_server_main;
127 FD_CLR (conn->fd, fdset);
128 ssm->nfds = get_nfds ();
133 conn_pool_expand (size_t expand_size)
135 sock_server_main_t *ssm = &sock_server_main;
136 sock_server_conn_t *conn_pool;
137 size_t new_size = ssm->conn_pool_size + expand_size;
140 conn_pool = realloc (ssm->conn_pool, new_size * sizeof (*ssm->conn_pool));
143 for (i = ssm->conn_pool_size; i < new_size; i++)
145 sock_server_conn_t *conn = &conn_pool[i];
146 memset (conn, 0, sizeof (*conn));
147 vcl_test_cfg_init (&conn->cfg);
148 vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
149 &conn->buf, &conn->buf_size);
150 conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
153 ssm->conn_pool = conn_pool;
154 ssm->conn_pool_size = new_size;
158 int errno_val = errno;
159 perror ("ERROR in conn_pool_expand()");
160 fprintf (stderr, "SERVER: ERROR: Memory allocation "
161 "failed (errno = %d)!\n", errno_val);
165 static inline sock_server_conn_t *
166 conn_pool_alloc (void)
168 sock_server_main_t *ssm = &sock_server_main;
171 for (i = 0; i < ssm->conn_pool_size; i++)
173 if (!ssm->conn_pool[i].is_alloc)
176 ssm->conn_pool[i].endpt.ip = ssm->conn_pool[i].ip;
178 ssm->conn_pool[i].is_alloc = 1;
179 return (&ssm->conn_pool[i]);
187 conn_pool_free (sock_server_conn_t * conn)
189 #if ! SOCK_SERVER_USE_EPOLL
190 sock_server_main_t *ssm = &sock_server_main;
192 conn_fdset_clr (conn, &ssm->rd_fdset);
193 conn_fdset_clr (conn, &ssm->wr_fdset);
200 sync_config_and_reply (sock_server_conn_t * conn, vcl_test_cfg_t * rx_cfg)
203 vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
204 &conn->buf, &conn->buf_size);
205 conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
207 if (conn->cfg.verbose)
209 printf ("\nSERVER (fd %d): Replying to cfg message!\n", conn->fd);
210 vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
212 (void) sock_test_write (conn->fd, (uint8_t *) & conn->cfg,
213 sizeof (conn->cfg), NULL, conn->cfg.verbose);
217 stream_test_server_start_stop (sock_server_conn_t * conn,
218 vcl_test_cfg_t * rx_cfg)
220 sock_server_main_t *ssm = &sock_server_main;
221 int client_fd = conn->fd;
222 vcl_test_t test = rx_cfg->test;
224 if (rx_cfg->ctrl_handle == conn->fd)
227 clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
229 for (i = 0; i < ssm->conn_pool_size; i++)
231 sock_server_conn_t *tc = &ssm->conn_pool[i];
233 if (tc->cfg.ctrl_handle == conn->fd)
235 vcl_test_stats_accumulate (&conn->stats, &tc->stats);
237 if (conn->cfg.verbose)
241 snprintf (buf, sizeof (buf), "SERVER (fd %d) RESULTS",
243 vcl_test_stats_dump (buf, &tc->stats, 1 /* show_rx */ ,
244 test == VCL_TEST_TYPE_BI
251 vcl_test_stats_dump ("SERVER RESULTS", &conn->stats, 1 /* show_rx */ ,
252 (test == VCL_TEST_TYPE_BI) /* show_tx */ ,
254 vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
255 if (conn->cfg.verbose)
257 printf (" sock server main\n"
258 VCL_TEST_SEPARATOR_STRING
260 " buf size: %u (0x%08x)\n"
261 VCL_TEST_SEPARATOR_STRING,
262 conn->buf, conn->buf_size, conn->buf_size);
265 sync_config_and_reply (conn, rx_cfg);
266 printf ("\nSERVER (fd %d): %s-directional Stream Test Complete!\n"
267 SOCK_TEST_BANNER_STRING "\n", conn->fd,
268 test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
272 printf ("\n" SOCK_TEST_BANNER_STRING
273 "SERVER (fd %d): %s-directional Stream Test!\n"
274 " Sending client the test cfg to start streaming data...\n",
275 client_fd, test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
277 rx_cfg->ctrl_handle = (rx_cfg->ctrl_handle == ~0) ? conn->fd :
280 sync_config_and_reply (conn, rx_cfg);
282 /* read the 1st chunk, record start time */
283 memset (&conn->stats, 0, sizeof (conn->stats));
284 clock_gettime (CLOCK_REALTIME, &conn->stats.start);
290 stream_test_server (sock_server_conn_t * conn, int rx_bytes)
292 int client_fd = conn->fd;
293 vcl_test_t test = conn->cfg.test;
295 if (test == VCL_TEST_TYPE_BI)
296 (void) sock_test_write (client_fd, conn->buf, rx_bytes, &conn->stats,
299 if (conn->stats.rx_bytes >= conn->cfg.total_bytes)
301 clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
305 #if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
309 sock_server_main_t *ssm = &sock_server_main;
310 int af_unix_client_fd;
314 size_t nbytes = strlen (SOCK_TEST_MIXED_EPOLL_DATA) + 1;
317 af_unix_client_fd = accept4 (ssm->af_unix_listen_fd,
318 (struct sockaddr *) NULL, NULL, NULL);
320 af_unix_client_fd = accept (ssm->af_unix_listen_fd,
321 (struct sockaddr *) NULL, NULL);
323 if (af_unix_client_fd < 0)
326 perror ("ERROR in af_unix_accept()");
327 fprintf (stderr, "SERVER: ERROR: accept failed "
328 "(errno = %d)!\n", errno_val);
332 printf ("SERVER: Got an AF_UNIX connection -- fd = %d (0x%08x)!\n",
333 af_unix_client_fd, af_unix_client_fd);
335 memset (buffer, 0, sizeof (buffer));
337 rv = read (af_unix_client_fd, buffer, nbytes);
341 perror ("ERROR in af_unix_echo(): read() failed");
342 fprintf (stderr, "SERVER: ERROR: read(af_unix_client_fd %d (0x%x), "
343 "nbytes %lu) failed (errno = %d)!\n", af_unix_client_fd,
344 af_unix_client_fd, nbytes, errno_val);
347 /* Make the buffer is NULL-terminated. */
348 buffer[sizeof (buffer) - 1] = 0;
349 printf ("SERVER (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
351 if (!strncmp (SOCK_TEST_MIXED_EPOLL_DATA, (const char *) buffer, nbytes))
353 rv = write (af_unix_client_fd, buffer, nbytes);
357 perror ("ERROR in af_unix_echo(): write() failed");
359 "SERVER: ERROR: write(af_unix_client_fd %d (0x%x), "
360 "\"%s\", nbytes %ld) failed (errno = %d)!\n",
361 af_unix_client_fd, af_unix_client_fd, buffer, nbytes,
365 printf ("SERVER (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer);
366 ssm->af_unix_xacts++;
369 close (af_unix_client_fd);
377 sock_server_main_t *ssm = &sock_server_main;
379 sock_server_conn_t *conn;
381 if (ssm->conn_pool_size < (ssm->num_conn + SOCK_SERVER_MAX_TEST_CONN + 1))
382 conn_pool_expand (SOCK_SERVER_MAX_TEST_CONN + 1);
384 conn = conn_pool_alloc ();
387 fprintf (stderr, "\nSERVER: ERROR: No free connections!\n");
392 client_fd = vppcom_session_accept (ssm->listen_fd, &conn->endpt, 0);
396 client_fd = accept4 (ssm->listen_fd, (struct sockaddr *) NULL, NULL, NULL);
398 client_fd = accept (ssm->listen_fd, (struct sockaddr *) NULL, NULL);
404 perror ("ERROR in new_client()");
405 fprintf (stderr, "SERVER: ERROR: accept failed "
406 "(errno = %d)!\n", errno_val);
410 printf ("SERVER: Got a connection -- fd = %d (0x%08x)!\n",
411 client_fd, client_fd);
413 conn->fd = client_fd;
415 #if ! SOCK_SERVER_USE_EPOLL
416 conn_fdset_set (conn, &ssm->rd_fdset);
420 struct epoll_event ev;
424 ev.data.u64 = conn - ssm->conn_pool;
426 rv = vppcom_epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, client_fd, &ev);
430 rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, client_fd, &ev);
436 perror ("ERROR in new_client()");
437 fprintf (stderr, "SERVER: ERROR: epoll_ctl failed (errno = %d)!\n",
447 print_usage_and_exit (void)
450 "sock_test_server [OPTIONS] <port>\n"
452 " -h Print this message and exit.\n"
454 " -u Use UDP transport layer\n");
459 main (int argc, char **argv)
461 sock_server_main_t *ssm = &sock_server_main;
462 int client_fd, rv, main_rv = 0;
463 int tx_bytes, rx_bytes, nbytes;
464 sock_server_conn_t *conn;
465 vcl_test_cfg_t *rx_cfg;
467 uint64_t xtra_bytes = 0;
468 struct sockaddr_storage servaddr;
471 uint16_t port = VCL_TEST_SERVER_PORT;
472 #if ! SOCK_SERVER_USE_EPOLL
473 fd_set _rfdset, *rfdset = &_rfdset;
476 vppcom_endpt_t endpt;
478 uint32_t servaddr_size;
479 #if ! SOCK_SERVER_USE_EPOLL
480 fd_set _wfdset, *wfdset = &_wfdset;
485 while ((c = getopt (argc, argv, "6D")) != -1)
489 ssm->cfg.address_ip6 = 1;
493 ssm->cfg.transport_udp = 1;
500 if (isprint (optopt))
501 fprintf (stderr, "SERVER: ERROR: Unknown "
502 "option `-%c'.\n", optopt);
504 fprintf (stderr, "SERVER: ERROR: Unknown "
505 "option character `\\x%x'.\n", optopt);
510 print_usage_and_exit ();
513 if (argc < (optind + 1))
515 fprintf (stderr, "SERVER: ERROR: Insufficient number of arguments!\n");
516 print_usage_and_exit ();
519 if (sscanf (argv[optind], "%d", &v) == 1)
523 fprintf (stderr, "SERVER: ERROR: Invalid port (%s)!\n", argv[optind]);
524 print_usage_and_exit ();
527 conn_pool_expand (SOCK_SERVER_MAX_TEST_CONN + 1);
530 rv = vppcom_app_create ("vcl_test_server");
538 ssm->listen_fd = vppcom_session_create (ssm->cfg.transport_udp ?
541 0 /* is_nonblocking */ );
544 ssm->listen_fd = socket (ssm->cfg.address_ip6 ? AF_INET6 : AF_INET,
545 ssm->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM,
547 #if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
548 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
549 ssm->af_unix_listen_fd = socket (AF_UNIX, SOCK_STREAM, 0);
550 if (ssm->af_unix_listen_fd < 0)
553 perror ("ERROR in main(): socket(AF_UNIX) failed");
555 "SERVER: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed "
556 "(errno = %d)!\n", errno_val);
557 return ssm->af_unix_listen_fd;
560 memset (&ssm->serveraddr, 0, sizeof (ssm->serveraddr));
561 ssm->serveraddr.sun_family = AF_UNIX;
562 strncpy (ssm->serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME,
563 sizeof (ssm->serveraddr.sun_path));
565 rv = bind (ssm->af_unix_listen_fd, (struct sockaddr *) &ssm->serveraddr,
566 SUN_LEN (&ssm->serveraddr));
570 perror ("ERROR in main(): bind(SOCK_TEST_AF_UNIX_FILENAME) failed");
571 fprintf (stderr, "SERVER: ERROR: bind() fd %d, \"%s\": "
572 "failed (errno = %d)!\n", ssm->af_unix_listen_fd,
573 SOCK_TEST_AF_UNIX_FILENAME, errno_val);
574 close (ssm->af_unix_listen_fd);
575 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
579 rv = listen (ssm->af_unix_listen_fd, 10);
583 perror ("ERROR in main(): listen(AF_UNIX) failed");
584 fprintf (stderr, "SERVER: ERROR: listen() fd %d, \"%s\": "
585 "failed (errno = %d)!\n", ssm->af_unix_listen_fd,
586 SOCK_TEST_AF_UNIX_FILENAME, errno_val);
587 close (ssm->af_unix_listen_fd);
588 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
591 #endif /* SOCK_SERVER_USE_EPOLL */
593 if (ssm->listen_fd < 0)
596 perror ("ERROR in main()");
597 fprintf (stderr, "SERVER: ERROR: socket() failed "
598 "(errno = %d)!\n", errno_val);
599 return ssm->listen_fd;
602 memset (&servaddr, 0, sizeof (servaddr));
604 if (ssm->cfg.address_ip6)
606 struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) &servaddr;
608 servaddr_size = sizeof (*server_addr);
610 server_addr->sin6_family = AF_INET6;
611 server_addr->sin6_addr = in6addr_any;
612 server_addr->sin6_port = htons (port);
616 struct sockaddr_in *server_addr = (struct sockaddr_in *) &servaddr;
618 servaddr_size = sizeof (*server_addr);
620 server_addr->sin_family = AF_INET;
621 server_addr->sin_addr.s_addr = htonl (INADDR_ANY);
622 server_addr->sin_port = htons (port);
626 if (ssm->cfg.address_ip6)
628 struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) &servaddr;
630 endpt.ip = (uint8_t *) & server_addr->sin6_addr;
631 endpt.port = (uint16_t) server_addr->sin6_port;
635 struct sockaddr_in *server_addr = (struct sockaddr_in *) &servaddr;
637 endpt.ip = (uint8_t *) & server_addr->sin_addr;
638 endpt.port = (uint16_t) server_addr->sin_port;
641 rv = vppcom_session_bind (ssm->listen_fd, &endpt);
648 rv = bind (ssm->listen_fd, (struct sockaddr *) &servaddr, servaddr_size);
653 perror ("ERROR in main()");
654 fprintf (stderr, "SERVER: ERROR: bind failed (errno = %d)!\n",
658 if (fcntl (ssm->listen_fd, F_SETFL, O_NONBLOCK) < 0)
661 perror ("ERROR in main()");
662 fprintf (stderr, "SERVER: ERROR: fcntl failed (errno = %d)!\n",
668 rv = vppcom_session_listen (ssm->listen_fd, 10);
675 rv = listen (ssm->listen_fd, 10);
680 perror ("ERROR in main()");
681 fprintf (stderr, "SERVER: ERROR: listen failed "
682 "(errno = %d)!\n", errno_val);
686 #if ! SOCK_SERVER_USE_EPOLL
688 FD_ZERO (&ssm->wr_fdset);
689 FD_ZERO (&ssm->rd_fdset);
691 FD_SET (ssm->listen_fd, &ssm->rd_fdset);
692 ssm->nfds = ssm->listen_fd + 1;
696 ssm->epfd = vppcom_epoll_create ();
700 ssm->epfd = epoll_create (1);
705 perror ("ERROR in main()");
706 fprintf (stderr, "SERVER: ERROR: epoll_create failed (errno = %d)!\n",
711 ssm->listen_ev.events = EPOLLIN;
712 ssm->listen_ev.data.u32 = ~0;
714 rv = vppcom_epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->listen_fd,
719 ssm->af_unix_listen_ev.events = EPOLLIN;
720 ssm->af_unix_listen_ev.data.u32 = SOCK_TEST_AF_UNIX_ACCEPT_DATA;
721 rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->af_unix_listen_fd,
722 &ssm->af_unix_listen_ev);
726 perror ("ERROR in main(): mixed epoll_ctl(EPOLL_CTL_ADD)");
727 fprintf (stderr, "SERVER: ERROR: mixed epoll_ctl(epfd %d (0x%x), "
728 "EPOLL_CTL_ADD, af_unix_listen_fd %d (0x%x), EPOLLIN) failed "
729 "(errno = %d)!\n", ssm->epfd, ssm->epfd,
730 ssm->af_unix_listen_fd, ssm->af_unix_listen_fd, errno_val);
731 close (ssm->af_unix_listen_fd);
732 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
736 rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->listen_fd, &ssm->listen_ev);
741 perror ("ERROR in main()");
742 fprintf (stderr, "SERVER: ERROR: epoll_ctl failed "
743 "(errno = %d)!\n", errno_val);
748 printf ("\nSERVER: Waiting for a client to connect on port %d...\n", port);
752 #if ! SOCK_SERVER_USE_EPOLL
753 _rfdset = ssm->rd_fdset;
756 rv = vppcom_select (ssm->nfds, (unsigned long *) rfdset, NULL, NULL, 0);
759 struct timeval timeout;
760 timeout = ssm->timeout;
761 _wfdset = ssm->wr_fdset;
762 rv = select (ssm->nfds, rfdset, wfdset, NULL, &timeout);
768 fprintf (stderr, "\nSERVER: ERROR: select() failed -- aborting!\n");
775 if (FD_ISSET (ssm->listen_fd, rfdset))
778 for (i = 0; i < ssm->conn_pool_size; i++)
780 if (!ssm->conn_pool[i].is_alloc)
783 conn = &ssm->conn_pool[i];
787 num_ev = vppcom_epoll_wait (ssm->epfd, ssm->wait_events,
788 SOCK_SERVER_MAX_EPOLL_EVENTS, 60.0);
792 num_ev = epoll_wait (ssm->epfd, ssm->wait_events,
793 SOCK_SERVER_MAX_EPOLL_EVENTS, 60000);
797 perror ("epoll_wait()");
798 fprintf (stderr, "\nSERVER: ERROR: epoll_wait() "
799 "failed -- aborting!\n");
805 fprintf (stderr, "\nSERVER: epoll_wait() timeout!\n");
808 for (i = 0; i < num_ev; i++)
810 conn = &ssm->conn_pool[ssm->wait_events[i].data.u32];
811 if (ssm->wait_events[i].events & (EPOLLHUP | EPOLLRDHUP))
814 vppcom_session_close (conn->fd);
820 if (ssm->wait_events[i].data.u32 == ~0)
825 #if !defined (VCL_TEST)
826 else if (ssm->wait_events[i].data.u32 ==
827 SOCK_TEST_AF_UNIX_ACCEPT_DATA)
834 client_fd = conn->fd;
836 #if ! SOCK_SERVER_USE_EPOLL
837 if (FD_ISSET (client_fd, rfdset))
839 if (EPOLLIN & ssm->wait_events[i].events)
843 rx_bytes = sock_test_read (client_fd, conn->buf,
844 conn->buf_size, &conn->stats);
847 rx_cfg = (vcl_test_cfg_t *) conn->buf;
848 if (rx_cfg->magic == VCL_TEST_CFG_CTRL_MAGIC)
852 printf ("SERVER (fd %d): Received a cfg message!\n",
854 vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
857 if (rx_bytes != sizeof (*rx_cfg))
859 printf ("SERVER (fd %d): Invalid cfg message "
860 "size (%d)!\n Should be %lu bytes.\n",
861 client_fd, rx_bytes, sizeof (*rx_cfg));
862 conn->cfg.rxbuf_size = 0;
863 conn->cfg.num_writes = 0;
864 if (conn->cfg.verbose)
866 printf ("SERVER (fd %d): Replying to "
867 "cfg message!\n", client_fd);
868 vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
870 sock_test_write (client_fd, (uint8_t *) & conn->cfg,
871 sizeof (conn->cfg), NULL,
876 switch (rx_cfg->test)
878 case VCL_TEST_TYPE_NONE:
879 case VCL_TEST_TYPE_ECHO:
880 sync_config_and_reply (conn, rx_cfg);
883 case VCL_TEST_TYPE_BI:
884 case VCL_TEST_TYPE_UNI:
885 stream_test_server_start_stop (conn, rx_cfg);
888 case VCL_TEST_TYPE_EXIT:
889 printf ("SERVER: Have a great day, "
890 "connection %d!\n", client_fd);
892 vppcom_session_close (client_fd);
896 conn_pool_free (conn);
897 printf ("SERVER: Closed client fd %d\n", client_fd);
898 #if ! SOCK_SERVER_USE_EPOLL
899 if (ssm->nfds == (ssm->listen_fd + 1))
905 printf ("SERVER: All client connections "
906 "closed.\n\nSERVER: "
907 "May the force be with you!\n\n");
914 "SERVER: ERROR: Unknown test type!\n");
915 vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
921 else if ((conn->cfg.test == VCL_TEST_TYPE_UNI) ||
922 (conn->cfg.test == VCL_TEST_TYPE_BI))
924 stream_test_server (conn, rx_bytes);
925 if (ioctl (conn->fd, FIONREAD))
930 else if (isascii (conn->buf[0]))
932 // If it looks vaguely like a string, make sure it's terminated
933 ((char *) conn->buf)[rx_bytes <
934 conn->buf_size ? rx_bytes :
935 conn->buf_size - 1] = 0;
936 printf ("SERVER (fd %d): RX (%d bytes) - '%s'\n",
937 conn->fd, rx_bytes, conn->buf);
942 if (errno == ECONNRESET)
944 printf ("\nSERVER: Connection reset by remote peer.\n"
945 " Y'all have a great day now!\n\n");
952 if (isascii (conn->buf[0]))
954 /* If it looks vaguely like a string,
955 * make sure it's terminated
957 ((char *) conn->buf)[rx_bytes <
958 conn->buf_size ? rx_bytes :
959 conn->buf_size - 1] = 0;
961 fprintf (stderr, "SERVER: ERROR: "
962 "FIFO not drained in previous test!\n"
963 " extra chunks %u (0x%x)\n"
964 " extra bytes %lu (0x%lx)\n",
965 xtra, xtra, xtra_bytes, xtra_bytes);
970 if (conn->cfg.verbose)
971 printf ("SERVER (fd %d): Echoing back\n", client_fd);
973 nbytes = strlen ((const char *) conn->buf) + 1;
975 tx_bytes = sock_test_write (client_fd, conn->buf,
976 nbytes, &conn->stats,
979 printf ("SERVER (fd %d): TX (%d bytes) - '%s'\n",
980 conn->fd, tx_bytes, conn->buf);
983 else // Extraneous read data from non-echo tests???
986 xtra_bytes += rx_bytes;
994 vppcom_session_close (ssm->listen_fd);
995 vppcom_app_destroy ();
997 close (ssm->listen_fd);
999 #if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
1000 close (ssm->af_unix_listen_fd);
1001 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
1002 #endif /* SOCK_SERVER_USE_EPOLL */
1006 free (ssm->conn_pool);
1012 * fd.io coding-style-patch-verification: ON
1015 * eval: (c-set-style "gnu")