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.
16 #ifndef __vcl_test_h__
17 #define __vcl_test_h__
23 #include <vcl/vppcom.h>
24 #include <vcl/sock_test_common.h>
27 vcl_test_read (int fd, uint8_t *buf, uint32_t nbytes,
28 sock_test_stats_t *stats)
30 int rx_bytes, errno_val;
36 rx_bytes = vppcom_session_read (fd, buf, nbytes);
45 if ((rx_bytes == 0) ||
46 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))))
48 else if (rx_bytes < nbytes)
52 while ((rx_bytes == 0) ||
53 ((rx_bytes < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))));
58 perror ("ERROR in sock_test_read()");
59 fprintf (stderr, "SOCK_TEST: ERROR: socket read "
60 "failed (errno = %d)!\n", errno_val);
64 stats->rx_bytes += rx_bytes;
70 vcl_test_write (int fd, uint8_t *buf, uint32_t nbytes,
71 sock_test_stats_t *stats, uint32_t verbose)
74 int nbytes_left = nbytes;
81 rv = vppcom_session_write (fd, buf, nbytes_left);
89 if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
100 if (tx_bytes != nbytes)
102 nbytes_left = nbytes_left - rv;
107 } while (tx_bytes != nbytes);
112 perror ("ERROR in sock_test_write()");
113 fprintf (stderr, "SOCK_TEST: ERROR: socket write failed "
114 "(errno = %d)!\n", errno_val);
117 stats->tx_bytes += tx_bytes;
122 #endif /* __vcl_test_h__ */