2 * Copyright (c) 2017 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 <vcl/sock_test.h>
28 #define SOCK_SERVER_USE_EPOLL 1
29 #define VPPCOM_SESSION_ATTR_UNIT_TEST 0
31 #if SOCK_SERVER_USE_EPOLL
32 #include <sys/epoll.h>
33 #if !defined(VCL_TEST)
39 #if VPPCOM_SESSION_ATTR_UNIT_TEST
40 #define BUFLEN sizeof (uint64_t) * 16
42 uint32_t buflen = BUFLEN;
43 uint32_t *flags = (uint32_t *) buffer;
54 sock_test_stats_t stats;
65 uint32_t transport_udp;
68 #define SOCK_SERVER_MAX_TEST_CONN 10
69 #define SOCK_SERVER_MAX_EPOLL_EVENTS 10
73 sock_server_cfg_t cfg;
74 #if SOCK_SERVER_USE_EPOLL
76 struct epoll_event listen_ev;
77 struct epoll_event wait_events[SOCK_SERVER_MAX_EPOLL_EVENTS];
78 #if !defined (VCL_TEST)
79 int af_unix_listen_fd;
81 struct epoll_event af_unix_listen_ev;
82 struct sockaddr_un serveraddr;
83 uint32_t af_unix_xacts;
87 size_t conn_pool_size;
88 sock_server_conn_t *conn_pool;
92 struct timeval timeout;
95 sock_server_main_t sock_server_main;
97 #if ! SOCK_SERVER_USE_EPOLL
101 sock_server_main_t *ssm = &sock_server_main;
104 for (nfds = i = 0; i < FD_SETSIZE; i++)
106 if (FD_ISSET (i, &ssm->rd_fdset) || FD_ISSET (i, &ssm->wr_fdset))
113 conn_fdset_set (sock_server_conn_t * conn, fd_set * fdset)
115 sock_server_main_t *ssm = &sock_server_main;
117 FD_SET (conn->fd, fdset);
118 ssm->nfds = get_nfds ();
122 conn_fdset_clr (sock_server_conn_t * conn, fd_set * fdset)
124 sock_server_main_t *ssm = &sock_server_main;
126 FD_CLR (conn->fd, fdset);
127 ssm->nfds = get_nfds ();
132 conn_pool_expand (size_t expand_size)
134 sock_server_main_t *ssm = &sock_server_main;
135 sock_server_conn_t *conn_pool;
136 size_t new_size = ssm->conn_pool_size + expand_size;
139 conn_pool = realloc (ssm->conn_pool, new_size * sizeof (*ssm->conn_pool));
142 for (i = ssm->conn_pool_size; i < new_size; i++)
144 sock_server_conn_t *conn = &conn_pool[i];
145 memset (conn, 0, sizeof (*conn));
146 sock_test_cfg_init (&conn->cfg);
147 sock_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
148 &conn->buf, &conn->buf_size);
149 conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
152 ssm->conn_pool = conn_pool;
153 ssm->conn_pool_size = new_size;
157 int errno_val = errno;
158 perror ("ERROR in conn_pool_expand()");
159 fprintf (stderr, "SERVER: ERROR: Memory allocation "
160 "failed (errno = %d)!\n", errno_val);
164 static inline sock_server_conn_t *
165 conn_pool_alloc (void)
167 sock_server_main_t *ssm = &sock_server_main;
170 for (i = 0; i < ssm->conn_pool_size; i++)
172 if (!ssm->conn_pool[i].is_alloc)
175 ssm->conn_pool[i].endpt.ip = ssm->conn_pool[i].ip;
177 ssm->conn_pool[i].is_alloc = 1;
178 return (&ssm->conn_pool[i]);
186 conn_pool_free (sock_server_conn_t * conn)
188 #if ! SOCK_SERVER_USE_EPOLL
189 sock_server_main_t *ssm = &sock_server_main;
191 conn_fdset_clr (conn, &ssm->rd_fdset);
192 conn_fdset_clr (conn, &ssm->wr_fdset);
199 sync_config_and_reply (sock_server_conn_t * conn, sock_test_cfg_t * rx_cfg)
202 sock_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
203 &conn->buf, &conn->buf_size);
204 conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
206 if (conn->cfg.verbose)
208 printf ("\nSERVER (fd %d): Replying to cfg message!\n", conn->fd);
209 sock_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
211 (void) sock_test_write (conn->fd, (uint8_t *) & conn->cfg,
212 sizeof (conn->cfg), NULL, conn->cfg.verbose);
216 stream_test_server_start_stop (sock_server_conn_t * conn,
217 sock_test_cfg_t * rx_cfg)
219 sock_server_main_t *ssm = &sock_server_main;
220 int client_fd = conn->fd;
221 sock_test_t test = rx_cfg->test;
223 if (rx_cfg->ctrl_handle == conn->fd)
226 clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
228 for (i = 0; i < ssm->conn_pool_size; i++)
230 sock_server_conn_t *tc = &ssm->conn_pool[i];
232 if (tc->cfg.ctrl_handle == conn->fd)
234 sock_test_stats_accumulate (&conn->stats, &tc->stats);
236 if (conn->cfg.verbose)
240 sprintf (buf, "SERVER (fd %d) RESULTS", tc->fd);
241 sock_test_stats_dump (buf, &tc->stats, 1 /* show_rx */ ,
242 test == SOCK_TEST_TYPE_BI
249 sock_test_stats_dump ("SERVER RESULTS", &conn->stats, 1 /* show_rx */ ,
250 (test == SOCK_TEST_TYPE_BI) /* show_tx */ ,
252 sock_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
253 if (conn->cfg.verbose)
255 printf (" sock server main\n"
256 SOCK_TEST_SEPARATOR_STRING
258 " buf size: %u (0x%08x)\n"
259 SOCK_TEST_SEPARATOR_STRING,
260 conn->buf, conn->buf_size, conn->buf_size);
263 sync_config_and_reply (conn, rx_cfg);
264 printf ("\nSERVER (fd %d): %s-directional Stream Test Complete!\n"
265 SOCK_TEST_BANNER_STRING "\n", conn->fd,
266 test == SOCK_TEST_TYPE_BI ? "Bi" : "Uni");
270 printf ("\n" SOCK_TEST_BANNER_STRING
271 "SERVER (fd %d): %s-directional Stream Test!\n"
272 " Sending client the test cfg to start streaming data...\n",
273 client_fd, test == SOCK_TEST_TYPE_BI ? "Bi" : "Uni");
275 rx_cfg->ctrl_handle = (rx_cfg->ctrl_handle == ~0) ? conn->fd :
278 sync_config_and_reply (conn, rx_cfg);
280 /* read the 1st chunk, record start time */
281 memset (&conn->stats, 0, sizeof (conn->stats));
282 clock_gettime (CLOCK_REALTIME, &conn->stats.start);
288 stream_test_server (sock_server_conn_t * conn, int rx_bytes)
290 int client_fd = conn->fd;
291 sock_test_t test = conn->cfg.test;
293 if (test == SOCK_TEST_TYPE_BI)
294 (void) sock_test_write (client_fd, conn->buf, rx_bytes, &conn->stats,
297 if (conn->stats.rx_bytes >= conn->cfg.total_bytes)
299 clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
303 #if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
307 sock_server_main_t *ssm = &sock_server_main;
308 int af_unix_client_fd;
312 size_t nbytes = strlen (SOCK_TEST_MIXED_EPOLL_DATA) + 1;
315 af_unix_client_fd = accept4 (ssm->af_unix_listen_fd,
316 (struct sockaddr *) NULL, NULL, NULL);
318 af_unix_client_fd = accept (ssm->af_unix_listen_fd,
319 (struct sockaddr *) NULL, NULL);
321 if (af_unix_client_fd < 0)
324 perror ("ERROR in af_unix_accept()");
325 fprintf (stderr, "SERVER: ERROR: accept failed "
326 "(errno = %d)!\n", errno_val);
330 printf ("SERVER: Got an AF_UNIX connection -- fd = %d (0x%08x)!\n",
331 af_unix_client_fd, af_unix_client_fd);
333 memset (buffer, 0, sizeof (buffer));
335 rv = read (af_unix_client_fd, buffer, nbytes);
339 perror ("ERROR in af_unix_echo(): read() failed");
340 fprintf (stderr, "SERVER: ERROR: read(af_unix_client_fd %d (0x%x), "
341 "\"%s\", nbytes %lu) failed (errno = %d)!\n",
342 af_unix_client_fd, af_unix_client_fd, buffer, nbytes,
347 printf ("SERVER (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
349 if (!strncmp (SOCK_TEST_MIXED_EPOLL_DATA, (const char *) buffer, nbytes))
351 rv = write (af_unix_client_fd, buffer, nbytes);
355 perror ("ERROR in af_unix_echo(): write() failed");
357 "SERVER: ERROR: write(af_unix_client_fd %d (0x%x), "
358 "\"%s\", nbytes %ld) failed (errno = %d)!\n",
359 af_unix_client_fd, af_unix_client_fd, buffer, nbytes,
363 printf ("SERVER (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer);
364 ssm->af_unix_xacts++;
367 close (af_unix_client_fd);
375 sock_server_main_t *ssm = &sock_server_main;
377 sock_server_conn_t *conn;
379 if (ssm->conn_pool_size < (ssm->num_conn + SOCK_SERVER_MAX_TEST_CONN + 1))
380 conn_pool_expand (SOCK_SERVER_MAX_TEST_CONN + 1);
382 conn = conn_pool_alloc ();
385 fprintf (stderr, "\nSERVER: ERROR: No free connections!\n");
390 client_fd = vppcom_session_accept (ssm->listen_fd, &conn->endpt, 0);
394 client_fd = accept4 (ssm->listen_fd, (struct sockaddr *) NULL, NULL, NULL);
396 client_fd = accept (ssm->listen_fd, (struct sockaddr *) NULL, NULL);
402 perror ("ERROR in new_client()");
403 fprintf (stderr, "SERVER: ERROR: accept failed "
404 "(errno = %d)!\n", errno_val);
408 printf ("SERVER: Got a connection -- fd = %d (0x%08x)!\n",
409 client_fd, client_fd);
411 conn->fd = client_fd;
413 #if ! SOCK_SERVER_USE_EPOLL
414 conn_fdset_set (conn, &ssm->rd_fdset);
418 struct epoll_event ev;
422 ev.data.u64 = conn - ssm->conn_pool;
424 rv = vppcom_epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, client_fd, &ev);
428 rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, client_fd, &ev);
434 perror ("ERROR in new_client()");
435 fprintf (stderr, "SERVER: ERROR: epoll_ctl failed (errno = %d)!\n",
445 print_usage_and_exit (void)
448 "sock_test_server [OPTIONS] <port>\n"
450 " -h Print this message and exit.\n"
452 " -u Use UDP transport layer\n");
457 main (int argc, char **argv)
459 sock_server_main_t *ssm = &sock_server_main;
460 int client_fd, rv, main_rv = 0;
461 int tx_bytes, rx_bytes, nbytes;
462 sock_server_conn_t *conn;
463 sock_test_cfg_t *rx_cfg;
465 uint64_t xtra_bytes = 0;
466 struct sockaddr_storage servaddr;
469 uint16_t port = SOCK_TEST_SERVER_PORT;
470 #if ! SOCK_SERVER_USE_EPOLL
471 fd_set _rfdset, *rfdset = &_rfdset;
474 vppcom_endpt_t endpt;
476 uint32_t servaddr_size;
477 #if ! SOCK_SERVER_USE_EPOLL
478 fd_set _wfdset, *wfdset = &_wfdset;
483 while ((c = getopt (argc, argv, "6D")) != -1)
487 ssm->cfg.address_ip6 = 1;
491 ssm->cfg.transport_udp = 1;
498 if (isprint (optopt))
499 fprintf (stderr, "SERVER: ERROR: Unknown "
500 "option `-%c'.\n", optopt);
502 fprintf (stderr, "SERVER: ERROR: Unknown "
503 "option character `\\x%x'.\n", optopt);
508 print_usage_and_exit ();
511 if (argc < (optind + 1))
513 fprintf (stderr, "SERVER: ERROR: Insufficient number of arguments!\n");
514 print_usage_and_exit ();
517 if (sscanf (argv[optind], "%d", &v) == 1)
521 fprintf (stderr, "SERVER: ERROR: Invalid port (%s)!\n", argv[optind]);
522 print_usage_and_exit ();
525 conn_pool_expand (SOCK_SERVER_MAX_TEST_CONN + 1);
528 rv = vppcom_app_create ("vcl_test_server");
536 ssm->listen_fd = vppcom_session_create (ssm->cfg.transport_udp ?
539 0 /* is_nonblocking */ );
542 ssm->listen_fd = socket (ssm->cfg.address_ip6 ? AF_INET6 : AF_INET,
543 ssm->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM,
545 #if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
546 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
547 ssm->af_unix_listen_fd = socket (AF_UNIX, SOCK_STREAM, 0);
548 if (ssm->af_unix_listen_fd < 0)
551 perror ("ERROR in main(): socket(AF_UNIX) failed");
553 "SERVER: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed "
554 "(errno = %d)!\n", errno_val);
555 return ssm->af_unix_listen_fd;
558 memset (&ssm->serveraddr, 0, sizeof (ssm->serveraddr));
559 ssm->serveraddr.sun_family = AF_UNIX;
560 strcpy (ssm->serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME);
562 rv = bind (ssm->af_unix_listen_fd, (struct sockaddr *) &ssm->serveraddr,
563 SUN_LEN (&ssm->serveraddr));
567 perror ("ERROR in main(): bind(SOCK_TEST_AF_UNIX_FILENAME) failed");
568 fprintf (stderr, "SERVER: ERROR: bind() fd %d, \"%s\": "
569 "failed (errno = %d)!\n", ssm->af_unix_listen_fd,
570 SOCK_TEST_AF_UNIX_FILENAME, errno_val);
571 close (ssm->af_unix_listen_fd);
572 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
576 rv = listen (ssm->af_unix_listen_fd, 10);
580 perror ("ERROR in main(): listen(AF_UNIX) failed");
581 fprintf (stderr, "SERVER: ERROR: listen() fd %d, \"%s\": "
582 "failed (errno = %d)!\n", ssm->af_unix_listen_fd,
583 SOCK_TEST_AF_UNIX_FILENAME, errno_val);
584 close (ssm->af_unix_listen_fd);
585 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
588 #endif /* SOCK_SERVER_USE_EPOLL */
590 if (ssm->listen_fd < 0)
593 perror ("ERROR in main()");
594 fprintf (stderr, "SERVER: ERROR: socket() failed "
595 "(errno = %d)!\n", errno_val);
596 return ssm->listen_fd;
599 memset (&servaddr, 0, sizeof (servaddr));
601 if (ssm->cfg.address_ip6)
603 struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) &servaddr;
605 servaddr_size = sizeof (*server_addr);
607 server_addr->sin6_family = AF_INET6;
608 server_addr->sin6_addr = in6addr_any;
609 server_addr->sin6_port = htons (port);
613 struct sockaddr_in *server_addr = (struct sockaddr_in *) &servaddr;
615 servaddr_size = sizeof (*server_addr);
617 server_addr->sin_family = AF_INET;
618 server_addr->sin_addr.s_addr = htonl (INADDR_ANY);
619 server_addr->sin_port = htons (port);
623 if (ssm->cfg.address_ip6)
625 struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) &servaddr;
627 endpt.ip = (uint8_t *) & server_addr->sin6_addr;
628 endpt.port = (uint16_t) server_addr->sin6_port;
632 struct sockaddr_in *server_addr = (struct sockaddr_in *) &servaddr;
634 endpt.ip = (uint8_t *) & server_addr->sin_addr;
635 endpt.port = (uint16_t) server_addr->sin_port;
638 rv = vppcom_session_bind (ssm->listen_fd, &endpt);
645 rv = bind (ssm->listen_fd, (struct sockaddr *) &servaddr, servaddr_size);
650 perror ("ERROR in main()");
651 fprintf (stderr, "SERVER: ERROR: bind failed (errno = %d)!\n",
657 rv = vppcom_session_listen (ssm->listen_fd, 10);
664 rv = listen (ssm->listen_fd, 10);
669 perror ("ERROR in main()");
670 fprintf (stderr, "SERVER: ERROR: listen failed "
671 "(errno = %d)!\n", errno_val);
675 #if ! SOCK_SERVER_USE_EPOLL
677 FD_ZERO (&ssm->wr_fdset);
678 FD_ZERO (&ssm->rd_fdset);
680 FD_SET (ssm->listen_fd, &ssm->rd_fdset);
681 ssm->nfds = ssm->listen_fd + 1;
685 ssm->epfd = vppcom_epoll_create ();
689 ssm->epfd = epoll_create (1);
694 perror ("ERROR in main()");
695 fprintf (stderr, "SERVER: ERROR: epoll_create failed (errno = %d)!\n",
700 ssm->listen_ev.events = EPOLLIN;
701 ssm->listen_ev.data.u32 = ~0;
703 rv = vppcom_epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->listen_fd,
708 ssm->af_unix_listen_ev.events = EPOLLIN;
709 ssm->af_unix_listen_ev.data.u32 = SOCK_TEST_AF_UNIX_ACCEPT_DATA;
710 rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->af_unix_listen_fd,
711 &ssm->af_unix_listen_ev);
715 perror ("ERROR in main(): mixed epoll_ctl(EPOLL_CTL_ADD)");
716 fprintf (stderr, "SERVER: ERROR: mixed epoll_ctl(epfd %d (0x%x), "
717 "EPOLL_CTL_ADD, af_unix_listen_fd %d (0x%x), EPOLLIN) failed "
718 "(errno = %d)!\n", ssm->epfd, ssm->epfd,
719 ssm->af_unix_listen_fd, ssm->af_unix_listen_fd, errno_val);
720 close (ssm->af_unix_listen_fd);
721 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
725 rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->listen_fd, &ssm->listen_ev);
730 perror ("ERROR in main()");
731 fprintf (stderr, "SERVER: ERROR: epoll_ctl failed "
732 "(errno = %d)!\n", errno_val);
737 printf ("\nSERVER: Waiting for a client to connect on port %d...\n", port);
741 #if ! SOCK_SERVER_USE_EPOLL
742 _rfdset = ssm->rd_fdset;
745 rv = vppcom_select (ssm->nfds, (uint64_t *) rfdset, NULL, NULL, 0);
748 struct timeval timeout;
749 timeout = ssm->timeout;
750 _wfdset = ssm->wr_fdset;
751 rv = select (ssm->nfds, rfdset, wfdset, NULL, &timeout);
757 fprintf (stderr, "\nSERVER: ERROR: select() failed -- aborting!\n");
764 if (FD_ISSET (ssm->listen_fd, rfdset))
767 for (i = 0; i < ssm->conn_pool_size; i++)
769 if (!ssm->conn_pool[i].is_alloc)
772 conn = &ssm->conn_pool[i];
776 num_ev = vppcom_epoll_wait (ssm->epfd, ssm->wait_events,
777 SOCK_SERVER_MAX_EPOLL_EVENTS, 60.0);
781 num_ev = epoll_wait (ssm->epfd, ssm->wait_events,
782 SOCK_SERVER_MAX_EPOLL_EVENTS, 60000);
786 perror ("epoll_wait()");
787 fprintf (stderr, "\nSERVER: ERROR: epoll_wait() "
788 "failed -- aborting!\n");
794 fprintf (stderr, "\nSERVER: epoll_wait() timeout!\n");
797 for (i = 0; i < num_ev; i++)
799 conn = &ssm->conn_pool[ssm->wait_events[i].data.u32];
800 if (ssm->wait_events[i].events & (EPOLLHUP | EPOLLRDHUP))
803 vppcom_session_close (conn->fd);
809 if (ssm->wait_events[i].data.u32 == ~0)
814 #if !defined (VCL_TEST)
815 else if (ssm->wait_events[i].data.u32 ==
816 SOCK_TEST_AF_UNIX_ACCEPT_DATA)
823 client_fd = conn->fd;
825 #if ! SOCK_SERVER_USE_EPOLL
826 if (FD_ISSET (client_fd, rfdset))
828 if (EPOLLIN & ssm->wait_events[i].events)
831 rx_bytes = sock_test_read (client_fd, conn->buf,
832 conn->buf_size, &conn->stats);
835 rx_cfg = (sock_test_cfg_t *) conn->buf;
836 if (rx_cfg->magic == SOCK_TEST_CFG_CTRL_MAGIC)
840 printf ("SERVER (fd %d): Received a cfg message!\n",
842 sock_test_cfg_dump (rx_cfg, 0 /* is_client */ );
845 if (rx_bytes != sizeof (*rx_cfg))
847 printf ("SERVER (fd %d): Invalid cfg message "
848 "size (%d)!\n Should be %lu bytes.\n",
849 client_fd, rx_bytes, sizeof (*rx_cfg));
850 conn->cfg.rxbuf_size = 0;
851 conn->cfg.num_writes = 0;
852 if (conn->cfg.verbose)
854 printf ("SERVER (fd %d): Replying to "
855 "cfg message!\n", client_fd);
856 sock_test_cfg_dump (rx_cfg, 0 /* is_client */ );
858 sock_test_write (client_fd, (uint8_t *) & conn->cfg,
859 sizeof (conn->cfg), NULL,
864 switch (rx_cfg->test)
866 case SOCK_TEST_TYPE_NONE:
867 case SOCK_TEST_TYPE_ECHO:
868 sync_config_and_reply (conn, rx_cfg);
871 case SOCK_TEST_TYPE_BI:
872 case SOCK_TEST_TYPE_UNI:
873 stream_test_server_start_stop (conn, rx_cfg);
876 case SOCK_TEST_TYPE_EXIT:
877 printf ("SERVER: Have a great day, "
878 "connection %d!\n", client_fd);
880 vppcom_session_close (client_fd);
884 conn_pool_free (conn);
885 printf ("SERVER: Closed client fd %d\n", client_fd);
886 #if ! SOCK_SERVER_USE_EPOLL
887 if (ssm->nfds == (ssm->listen_fd + 1))
893 printf ("SERVER: All client connections "
894 "closed.\n\nSERVER: "
895 "May the force be with you!\n\n");
902 "SERVER: ERROR: Unknown test type!\n");
903 sock_test_cfg_dump (rx_cfg, 0 /* is_client */ );
909 else if ((conn->cfg.test == SOCK_TEST_TYPE_UNI) ||
910 (conn->cfg.test == SOCK_TEST_TYPE_BI))
912 stream_test_server (conn, rx_bytes);
916 else if (isascii (conn->buf[0]))
918 // If it looks vaguely like a string, make sure it's terminated
919 ((char *) conn->buf)[rx_bytes <
920 conn->buf_size ? rx_bytes :
921 conn->buf_size - 1] = 0;
922 printf ("SERVER (fd %d): RX (%d bytes) - '%s'\n",
923 conn->fd, rx_bytes, conn->buf);
928 if (errno == ECONNRESET)
930 printf ("\nSERVER: Connection reset by remote peer.\n"
931 " Y'all have a great day now!\n\n");
938 if (isascii (conn->buf[0]))
940 /* If it looks vaguely like a string,
941 * make sure it's terminated
943 ((char *) conn->buf)[rx_bytes <
944 conn->buf_size ? rx_bytes :
945 conn->buf_size - 1] = 0;
947 fprintf (stderr, "SERVER: ERROR: "
948 "FIFO not drained in previous test!\n"
949 " extra chunks %u (0x%x)\n"
950 " extra bytes %lu (0x%lx)\n",
951 xtra, xtra, xtra_bytes, xtra_bytes);
956 if (conn->cfg.verbose)
957 printf ("SERVER (fd %d): Echoing back\n", client_fd);
959 nbytes = strlen ((const char *) conn->buf) + 1;
961 tx_bytes = sock_test_write (client_fd, conn->buf,
962 nbytes, &conn->stats,
965 printf ("SERVER (fd %d): TX (%d bytes) - '%s'\n",
966 conn->fd, tx_bytes, conn->buf);
969 else // Extraneous read data from non-echo tests???
972 xtra_bytes += rx_bytes;
980 vppcom_session_close (ssm->listen_fd);
981 vppcom_app_destroy ();
983 close (ssm->listen_fd);
985 #if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
986 close (ssm->af_unix_listen_fd);
987 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
988 #endif /* SOCK_SERVER_USE_EPOLL */
992 free (ssm->conn_pool);
998 * fd.io coding-style-patch-verification: ON
1001 * eval: (c-set-style "gnu")