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>
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 sprintf (buf, "SERVER (fd %d) RESULTS", tc->fd);
242 vcl_test_stats_dump (buf, &tc->stats, 1 /* show_rx */ ,
243 test == VCL_TEST_TYPE_BI
250 vcl_test_stats_dump ("SERVER RESULTS", &conn->stats, 1 /* show_rx */ ,
251 (test == VCL_TEST_TYPE_BI) /* show_tx */ ,
253 vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
254 if (conn->cfg.verbose)
256 printf (" sock server main\n"
257 VCL_TEST_SEPARATOR_STRING
259 " buf size: %u (0x%08x)\n"
260 VCL_TEST_SEPARATOR_STRING,
261 conn->buf, conn->buf_size, conn->buf_size);
264 sync_config_and_reply (conn, rx_cfg);
265 printf ("\nSERVER (fd %d): %s-directional Stream Test Complete!\n"
266 SOCK_TEST_BANNER_STRING "\n", conn->fd,
267 test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
271 printf ("\n" SOCK_TEST_BANNER_STRING
272 "SERVER (fd %d): %s-directional Stream Test!\n"
273 " Sending client the test cfg to start streaming data...\n",
274 client_fd, test == VCL_TEST_TYPE_BI ? "Bi" : "Uni");
276 rx_cfg->ctrl_handle = (rx_cfg->ctrl_handle == ~0) ? conn->fd :
279 sync_config_and_reply (conn, rx_cfg);
281 /* read the 1st chunk, record start time */
282 memset (&conn->stats, 0, sizeof (conn->stats));
283 clock_gettime (CLOCK_REALTIME, &conn->stats.start);
289 stream_test_server (sock_server_conn_t * conn, int rx_bytes)
291 int client_fd = conn->fd;
292 vcl_test_t test = conn->cfg.test;
294 if (test == VCL_TEST_TYPE_BI)
295 (void) sock_test_write (client_fd, conn->buf, rx_bytes, &conn->stats,
298 if (conn->stats.rx_bytes >= conn->cfg.total_bytes)
300 clock_gettime (CLOCK_REALTIME, &conn->stats.stop);
304 #if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
308 sock_server_main_t *ssm = &sock_server_main;
309 int af_unix_client_fd;
313 size_t nbytes = strlen (SOCK_TEST_MIXED_EPOLL_DATA) + 1;
316 af_unix_client_fd = accept4 (ssm->af_unix_listen_fd,
317 (struct sockaddr *) NULL, NULL, NULL);
319 af_unix_client_fd = accept (ssm->af_unix_listen_fd,
320 (struct sockaddr *) NULL, NULL);
322 if (af_unix_client_fd < 0)
325 perror ("ERROR in af_unix_accept()");
326 fprintf (stderr, "SERVER: ERROR: accept failed "
327 "(errno = %d)!\n", errno_val);
331 printf ("SERVER: Got an AF_UNIX connection -- fd = %d (0x%08x)!\n",
332 af_unix_client_fd, af_unix_client_fd);
334 memset (buffer, 0, sizeof (buffer));
336 rv = read (af_unix_client_fd, buffer, nbytes);
340 perror ("ERROR in af_unix_echo(): read() failed");
341 fprintf (stderr, "SERVER: ERROR: read(af_unix_client_fd %d (0x%x), "
342 "\"%s\", nbytes %lu) failed (errno = %d)!\n",
343 af_unix_client_fd, af_unix_client_fd, buffer, nbytes,
348 printf ("SERVER (AF_UNIX): RX (%d bytes) - '%s'\n", rv, buffer);
350 if (!strncmp (SOCK_TEST_MIXED_EPOLL_DATA, (const char *) buffer, nbytes))
352 rv = write (af_unix_client_fd, buffer, nbytes);
356 perror ("ERROR in af_unix_echo(): write() failed");
358 "SERVER: ERROR: write(af_unix_client_fd %d (0x%x), "
359 "\"%s\", nbytes %ld) failed (errno = %d)!\n",
360 af_unix_client_fd, af_unix_client_fd, buffer, nbytes,
364 printf ("SERVER (AF_UNIX): TX (%d bytes) - '%s'\n", rv, buffer);
365 ssm->af_unix_xacts++;
368 close (af_unix_client_fd);
376 sock_server_main_t *ssm = &sock_server_main;
378 sock_server_conn_t *conn;
380 if (ssm->conn_pool_size < (ssm->num_conn + SOCK_SERVER_MAX_TEST_CONN + 1))
381 conn_pool_expand (SOCK_SERVER_MAX_TEST_CONN + 1);
383 conn = conn_pool_alloc ();
386 fprintf (stderr, "\nSERVER: ERROR: No free connections!\n");
391 client_fd = vppcom_session_accept (ssm->listen_fd, &conn->endpt, 0);
395 client_fd = accept4 (ssm->listen_fd, (struct sockaddr *) NULL, NULL, NULL);
397 client_fd = accept (ssm->listen_fd, (struct sockaddr *) NULL, NULL);
403 perror ("ERROR in new_client()");
404 fprintf (stderr, "SERVER: ERROR: accept failed "
405 "(errno = %d)!\n", errno_val);
409 printf ("SERVER: Got a connection -- fd = %d (0x%08x)!\n",
410 client_fd, client_fd);
412 conn->fd = client_fd;
414 #if ! SOCK_SERVER_USE_EPOLL
415 conn_fdset_set (conn, &ssm->rd_fdset);
419 struct epoll_event ev;
423 ev.data.u64 = conn - ssm->conn_pool;
425 rv = vppcom_epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, client_fd, &ev);
429 rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, client_fd, &ev);
435 perror ("ERROR in new_client()");
436 fprintf (stderr, "SERVER: ERROR: epoll_ctl failed (errno = %d)!\n",
446 print_usage_and_exit (void)
449 "sock_test_server [OPTIONS] <port>\n"
451 " -h Print this message and exit.\n"
453 " -u Use UDP transport layer\n");
458 main (int argc, char **argv)
460 sock_server_main_t *ssm = &sock_server_main;
461 int client_fd, rv, main_rv = 0;
462 int tx_bytes, rx_bytes, nbytes;
463 sock_server_conn_t *conn;
464 vcl_test_cfg_t *rx_cfg;
466 uint64_t xtra_bytes = 0;
467 struct sockaddr_storage servaddr;
470 uint16_t port = VCL_TEST_SERVER_PORT;
471 #if ! SOCK_SERVER_USE_EPOLL
472 fd_set _rfdset, *rfdset = &_rfdset;
475 vppcom_endpt_t endpt;
477 uint32_t servaddr_size;
478 #if ! SOCK_SERVER_USE_EPOLL
479 fd_set _wfdset, *wfdset = &_wfdset;
484 while ((c = getopt (argc, argv, "6D")) != -1)
488 ssm->cfg.address_ip6 = 1;
492 ssm->cfg.transport_udp = 1;
499 if (isprint (optopt))
500 fprintf (stderr, "SERVER: ERROR: Unknown "
501 "option `-%c'.\n", optopt);
503 fprintf (stderr, "SERVER: ERROR: Unknown "
504 "option character `\\x%x'.\n", optopt);
509 print_usage_and_exit ();
512 if (argc < (optind + 1))
514 fprintf (stderr, "SERVER: ERROR: Insufficient number of arguments!\n");
515 print_usage_and_exit ();
518 if (sscanf (argv[optind], "%d", &v) == 1)
522 fprintf (stderr, "SERVER: ERROR: Invalid port (%s)!\n", argv[optind]);
523 print_usage_and_exit ();
526 conn_pool_expand (SOCK_SERVER_MAX_TEST_CONN + 1);
529 rv = vppcom_app_create ("vcl_test_server");
537 ssm->listen_fd = vppcom_session_create (ssm->cfg.transport_udp ?
540 0 /* is_nonblocking */ );
543 ssm->listen_fd = socket (ssm->cfg.address_ip6 ? AF_INET6 : AF_INET,
544 ssm->cfg.transport_udp ? SOCK_DGRAM : SOCK_STREAM,
546 #if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
547 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
548 ssm->af_unix_listen_fd = socket (AF_UNIX, SOCK_STREAM, 0);
549 if (ssm->af_unix_listen_fd < 0)
552 perror ("ERROR in main(): socket(AF_UNIX) failed");
554 "SERVER: ERROR: socket(AF_UNIX, SOCK_STREAM, 0) failed "
555 "(errno = %d)!\n", errno_val);
556 return ssm->af_unix_listen_fd;
559 memset (&ssm->serveraddr, 0, sizeof (ssm->serveraddr));
560 ssm->serveraddr.sun_family = AF_UNIX;
561 strcpy (ssm->serveraddr.sun_path, SOCK_TEST_AF_UNIX_FILENAME);
563 rv = bind (ssm->af_unix_listen_fd, (struct sockaddr *) &ssm->serveraddr,
564 SUN_LEN (&ssm->serveraddr));
568 perror ("ERROR in main(): bind(SOCK_TEST_AF_UNIX_FILENAME) failed");
569 fprintf (stderr, "SERVER: ERROR: bind() fd %d, \"%s\": "
570 "failed (errno = %d)!\n", ssm->af_unix_listen_fd,
571 SOCK_TEST_AF_UNIX_FILENAME, errno_val);
572 close (ssm->af_unix_listen_fd);
573 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
577 rv = listen (ssm->af_unix_listen_fd, 10);
581 perror ("ERROR in main(): listen(AF_UNIX) failed");
582 fprintf (stderr, "SERVER: ERROR: listen() fd %d, \"%s\": "
583 "failed (errno = %d)!\n", ssm->af_unix_listen_fd,
584 SOCK_TEST_AF_UNIX_FILENAME, errno_val);
585 close (ssm->af_unix_listen_fd);
586 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
589 #endif /* SOCK_SERVER_USE_EPOLL */
591 if (ssm->listen_fd < 0)
594 perror ("ERROR in main()");
595 fprintf (stderr, "SERVER: ERROR: socket() failed "
596 "(errno = %d)!\n", errno_val);
597 return ssm->listen_fd;
600 memset (&servaddr, 0, sizeof (servaddr));
602 if (ssm->cfg.address_ip6)
604 struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) &servaddr;
606 servaddr_size = sizeof (*server_addr);
608 server_addr->sin6_family = AF_INET6;
609 server_addr->sin6_addr = in6addr_any;
610 server_addr->sin6_port = htons (port);
614 struct sockaddr_in *server_addr = (struct sockaddr_in *) &servaddr;
616 servaddr_size = sizeof (*server_addr);
618 server_addr->sin_family = AF_INET;
619 server_addr->sin_addr.s_addr = htonl (INADDR_ANY);
620 server_addr->sin_port = htons (port);
624 if (ssm->cfg.address_ip6)
626 struct sockaddr_in6 *server_addr = (struct sockaddr_in6 *) &servaddr;
628 endpt.ip = (uint8_t *) & server_addr->sin6_addr;
629 endpt.port = (uint16_t) server_addr->sin6_port;
633 struct sockaddr_in *server_addr = (struct sockaddr_in *) &servaddr;
635 endpt.ip = (uint8_t *) & server_addr->sin_addr;
636 endpt.port = (uint16_t) server_addr->sin_port;
639 rv = vppcom_session_bind (ssm->listen_fd, &endpt);
646 rv = bind (ssm->listen_fd, (struct sockaddr *) &servaddr, servaddr_size);
651 perror ("ERROR in main()");
652 fprintf (stderr, "SERVER: ERROR: bind failed (errno = %d)!\n",
656 if (fcntl (ssm->listen_fd, F_SETFL, O_NONBLOCK) < 0)
659 perror ("ERROR in main()");
660 fprintf (stderr, "SERVER: ERROR: fcntl failed (errno = %d)!\n",
666 rv = vppcom_session_listen (ssm->listen_fd, 10);
673 rv = listen (ssm->listen_fd, 10);
678 perror ("ERROR in main()");
679 fprintf (stderr, "SERVER: ERROR: listen failed "
680 "(errno = %d)!\n", errno_val);
684 #if ! SOCK_SERVER_USE_EPOLL
686 FD_ZERO (&ssm->wr_fdset);
687 FD_ZERO (&ssm->rd_fdset);
689 FD_SET (ssm->listen_fd, &ssm->rd_fdset);
690 ssm->nfds = ssm->listen_fd + 1;
694 ssm->epfd = vppcom_epoll_create ();
698 ssm->epfd = epoll_create (1);
703 perror ("ERROR in main()");
704 fprintf (stderr, "SERVER: ERROR: epoll_create failed (errno = %d)!\n",
709 ssm->listen_ev.events = EPOLLIN;
710 ssm->listen_ev.data.u32 = ~0;
712 rv = vppcom_epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->listen_fd,
717 ssm->af_unix_listen_ev.events = EPOLLIN;
718 ssm->af_unix_listen_ev.data.u32 = SOCK_TEST_AF_UNIX_ACCEPT_DATA;
719 rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->af_unix_listen_fd,
720 &ssm->af_unix_listen_ev);
724 perror ("ERROR in main(): mixed epoll_ctl(EPOLL_CTL_ADD)");
725 fprintf (stderr, "SERVER: ERROR: mixed epoll_ctl(epfd %d (0x%x), "
726 "EPOLL_CTL_ADD, af_unix_listen_fd %d (0x%x), EPOLLIN) failed "
727 "(errno = %d)!\n", ssm->epfd, ssm->epfd,
728 ssm->af_unix_listen_fd, ssm->af_unix_listen_fd, errno_val);
729 close (ssm->af_unix_listen_fd);
730 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
734 rv = epoll_ctl (ssm->epfd, EPOLL_CTL_ADD, ssm->listen_fd, &ssm->listen_ev);
739 perror ("ERROR in main()");
740 fprintf (stderr, "SERVER: ERROR: epoll_ctl failed "
741 "(errno = %d)!\n", errno_val);
746 printf ("\nSERVER: Waiting for a client to connect on port %d...\n", port);
750 #if ! SOCK_SERVER_USE_EPOLL
751 _rfdset = ssm->rd_fdset;
754 rv = vppcom_select (ssm->nfds, (unsigned long *) rfdset, NULL, NULL, 0);
757 struct timeval timeout;
758 timeout = ssm->timeout;
759 _wfdset = ssm->wr_fdset;
760 rv = select (ssm->nfds, rfdset, wfdset, NULL, &timeout);
766 fprintf (stderr, "\nSERVER: ERROR: select() failed -- aborting!\n");
773 if (FD_ISSET (ssm->listen_fd, rfdset))
776 for (i = 0; i < ssm->conn_pool_size; i++)
778 if (!ssm->conn_pool[i].is_alloc)
781 conn = &ssm->conn_pool[i];
785 num_ev = vppcom_epoll_wait (ssm->epfd, ssm->wait_events,
786 SOCK_SERVER_MAX_EPOLL_EVENTS, 60.0);
790 num_ev = epoll_wait (ssm->epfd, ssm->wait_events,
791 SOCK_SERVER_MAX_EPOLL_EVENTS, 60000);
795 perror ("epoll_wait()");
796 fprintf (stderr, "\nSERVER: ERROR: epoll_wait() "
797 "failed -- aborting!\n");
803 fprintf (stderr, "\nSERVER: epoll_wait() timeout!\n");
806 for (i = 0; i < num_ev; i++)
808 conn = &ssm->conn_pool[ssm->wait_events[i].data.u32];
809 if (ssm->wait_events[i].events & (EPOLLHUP | EPOLLRDHUP))
812 vppcom_session_close (conn->fd);
818 if (ssm->wait_events[i].data.u32 == ~0)
823 #if !defined (VCL_TEST)
824 else if (ssm->wait_events[i].data.u32 ==
825 SOCK_TEST_AF_UNIX_ACCEPT_DATA)
832 client_fd = conn->fd;
834 #if ! SOCK_SERVER_USE_EPOLL
835 if (FD_ISSET (client_fd, rfdset))
837 if (EPOLLIN & ssm->wait_events[i].events)
841 rx_bytes = sock_test_read (client_fd, conn->buf,
842 conn->buf_size, &conn->stats);
845 rx_cfg = (vcl_test_cfg_t *) conn->buf;
846 if (rx_cfg->magic == VCL_TEST_CFG_CTRL_MAGIC)
850 printf ("SERVER (fd %d): Received a cfg message!\n",
852 vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
855 if (rx_bytes != sizeof (*rx_cfg))
857 printf ("SERVER (fd %d): Invalid cfg message "
858 "size (%d)!\n Should be %lu bytes.\n",
859 client_fd, rx_bytes, sizeof (*rx_cfg));
860 conn->cfg.rxbuf_size = 0;
861 conn->cfg.num_writes = 0;
862 if (conn->cfg.verbose)
864 printf ("SERVER (fd %d): Replying to "
865 "cfg message!\n", client_fd);
866 vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
868 sock_test_write (client_fd, (uint8_t *) & conn->cfg,
869 sizeof (conn->cfg), NULL,
874 switch (rx_cfg->test)
876 case VCL_TEST_TYPE_NONE:
877 case VCL_TEST_TYPE_ECHO:
878 sync_config_and_reply (conn, rx_cfg);
881 case VCL_TEST_TYPE_BI:
882 case VCL_TEST_TYPE_UNI:
883 stream_test_server_start_stop (conn, rx_cfg);
886 case VCL_TEST_TYPE_EXIT:
887 printf ("SERVER: Have a great day, "
888 "connection %d!\n", client_fd);
890 vppcom_session_close (client_fd);
894 conn_pool_free (conn);
895 printf ("SERVER: Closed client fd %d\n", client_fd);
896 #if ! SOCK_SERVER_USE_EPOLL
897 if (ssm->nfds == (ssm->listen_fd + 1))
903 printf ("SERVER: All client connections "
904 "closed.\n\nSERVER: "
905 "May the force be with you!\n\n");
912 "SERVER: ERROR: Unknown test type!\n");
913 vcl_test_cfg_dump (rx_cfg, 0 /* is_client */ );
919 else if ((conn->cfg.test == VCL_TEST_TYPE_UNI) ||
920 (conn->cfg.test == VCL_TEST_TYPE_BI))
922 stream_test_server (conn, rx_bytes);
923 if (ioctl (conn->fd, FIONREAD))
928 else if (isascii (conn->buf[0]))
930 // If it looks vaguely like a string, make sure it's terminated
931 ((char *) conn->buf)[rx_bytes <
932 conn->buf_size ? rx_bytes :
933 conn->buf_size - 1] = 0;
934 printf ("SERVER (fd %d): RX (%d bytes) - '%s'\n",
935 conn->fd, rx_bytes, conn->buf);
940 if (errno == ECONNRESET)
942 printf ("\nSERVER: Connection reset by remote peer.\n"
943 " Y'all have a great day now!\n\n");
950 if (isascii (conn->buf[0]))
952 /* If it looks vaguely like a string,
953 * make sure it's terminated
955 ((char *) conn->buf)[rx_bytes <
956 conn->buf_size ? rx_bytes :
957 conn->buf_size - 1] = 0;
959 fprintf (stderr, "SERVER: ERROR: "
960 "FIFO not drained in previous test!\n"
961 " extra chunks %u (0x%x)\n"
962 " extra bytes %lu (0x%lx)\n",
963 xtra, xtra, xtra_bytes, xtra_bytes);
968 if (conn->cfg.verbose)
969 printf ("SERVER (fd %d): Echoing back\n", client_fd);
971 nbytes = strlen ((const char *) conn->buf) + 1;
973 tx_bytes = sock_test_write (client_fd, conn->buf,
974 nbytes, &conn->stats,
977 printf ("SERVER (fd %d): TX (%d bytes) - '%s'\n",
978 conn->fd, tx_bytes, conn->buf);
981 else // Extraneous read data from non-echo tests???
984 xtra_bytes += rx_bytes;
992 vppcom_session_close (ssm->listen_fd);
993 vppcom_app_destroy ();
995 close (ssm->listen_fd);
997 #if SOCK_SERVER_USE_EPOLL && !defined (VCL_TEST)
998 close (ssm->af_unix_listen_fd);
999 unlink ((const char *) SOCK_TEST_AF_UNIX_FILENAME);
1000 #endif /* SOCK_SERVER_USE_EPOLL */
1004 free (ssm->conn_pool);
1010 * fd.io coding-style-patch-verification: ON
1013 * eval: (c-set-style "gnu")