61#if LWIP_TCP && LWIP_CALLBACK_API
64#ifndef LWIPERF_TCP_MAX_IDLE_SEC
65#define LWIPERF_TCP_MAX_IDLE_SEC 10U
67#if LWIPERF_TCP_MAX_IDLE_SEC > 255
68#error LWIPERF_TCP_MAX_IDLE_SEC must fit into an u8_t
72#ifndef LWIPERF_SERVER_IP_TYPE
73#define LWIPERF_SERVER_IP_TYPE IPADDR_TYPE_ANY
79#define LWIPERF_ALLOC(type) mem_malloc(sizeof(type))
80#define LWIPERF_FREE(type, item) mem_free(item)
84#ifndef LWIPERF_CHECK_RX_DATA
85#define LWIPERF_CHECK_RX_DATA 0
89typedef struct _lwiperf_settings {
90#define LWIPERF_FLAGS_ANSWER_TEST 0x80000000
91#define LWIPERF_FLAGS_ANSWER_NOW 0x00000001
101struct _lwiperf_state_base;
102typedef struct _lwiperf_state_base lwiperf_state_base_t;
103struct _lwiperf_state_base {
105 lwiperf_state_base_t *
next;
111 lwiperf_state_base_t *related_master_state;
115typedef struct _lwiperf_state_tcp {
116 lwiperf_state_base_t
base;
117 struct tcp_pcb *server_pcb;
118 struct tcp_pcb *conn_pcb;
125 u8_t client_tradeoff_mode;
126 u32_t bytes_transferred;
128 u8_t have_settings_buf;
129 u8_t specific_remote;
131} lwiperf_state_tcp_t;
134static lwiperf_state_base_t *lwiperf_all_connections;
136static const u8_t lwiperf_txbuf_const[1600] = {
137 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
138 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
139 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
140 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
141 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
142 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
143 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
144 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
145 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
146 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
147 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
148 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
149 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
150 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
151 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
152 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
153 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
154 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
155 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
156 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
157 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
158 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
159 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
160 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
161 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
162 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
163 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
164 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
165 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
166 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
167 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
168 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
169 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
170 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
171 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
172 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
173 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
174 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
175 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
176 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
179static err_t lwiperf_tcp_poll(
void *
arg,
struct tcp_pcb *tpcb);
183 lwiperf_state_base_t *related_master_state, lwiperf_state_tcp_t **
state);
188lwiperf_list_add(lwiperf_state_base_t *
item)
190 item->next = lwiperf_all_connections;
191 lwiperf_all_connections =
item;
196lwiperf_list_remove(lwiperf_state_base_t *
item)
198 lwiperf_state_base_t *prev =
NULL;
199 lwiperf_state_base_t *iter;
200 for (iter = lwiperf_all_connections; iter !=
NULL; prev = iter, iter = iter->
next) {
203 lwiperf_all_connections = iter->
next;
205 prev->next = iter->next;
208 for (iter = iter->next; iter !=
NULL; iter = iter->
next) {
216static lwiperf_state_base_t *
217lwiperf_list_find(lwiperf_state_base_t *
item)
219 lwiperf_state_base_t *iter;
220 for (iter = lwiperf_all_connections; iter !=
NULL; iter = iter->
next) {
232 if ((conn !=
NULL) && (conn->report_fn !=
NULL)) {
233 u32_t now, duration_ms, bandwidth_kbitpsec;
235 duration_ms =
now - conn->time_started;
236 if (duration_ms == 0) {
237 bandwidth_kbitpsec = 0;
239 bandwidth_kbitpsec = (conn->bytes_transferred / duration_ms) * 8U;
242 &conn->conn_pcb->local_ip, conn->conn_pcb->local_port,
243 &conn->conn_pcb->remote_ip, conn->conn_pcb->remote_port,
244 conn->bytes_transferred, duration_ms, bandwidth_kbitpsec);
254 lwiperf_list_remove(&conn->base);
256 if (conn->conn_pcb !=
NULL) {
257 tcp_arg(conn->conn_pcb,
NULL);
259 tcp_sent(conn->conn_pcb,
NULL);
261 tcp_err(conn->conn_pcb,
NULL);
265 tcp_abort(conn->conn_pcb);
267 }
else if (conn->server_pcb !=
NULL) {
272 LWIPERF_FREE(lwiperf_state_tcp_t, conn);
277lwiperf_tcp_client_send_more(lwiperf_state_tcp_t *conn)
286 LWIP_ASSERT(
"conn invalid", (conn !=
NULL) && conn->base.tcp && (conn->base.server == 0));
290 if (conn->settings.amount &
PP_HTONL(0x80000000)) {
293 u32_t diff_ms =
now - conn->time_started;
296 if (diff_ms >= time_ms) {
305 if (amount_bytes >= conn->bytes_transferred) {
312 if (conn->bytes_transferred < 24) {
314 txptr = &((
u8_t *)&conn->settings)[conn->bytes_transferred];
315 txlen_max = (
u16_t)(24 - conn->bytes_transferred);
316 apiflags = TCP_WRITE_FLAG_COPY;
317 }
else if (conn->bytes_transferred < 48) {
319 txptr = &((
u8_t *)&conn->settings)[conn->bytes_transferred - 24];
320 txlen_max = (
u16_t)(48 - conn->bytes_transferred);
321 apiflags = TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE;
326 txptr =
LWIP_CONST_CAST(
void *, &lwiperf_txbuf_const[conn->bytes_transferred % 10]);
328 if (conn->bytes_transferred == 48) {
336 err = tcp_write(conn->conn_pcb, txptr, txlen, apiflags);
343 conn->bytes_transferred += txlen;
349 tcp_output(conn->conn_pcb);
355lwiperf_tcp_client_sent(
void *
arg,
struct tcp_pcb *tpcb,
u16_t len)
357 lwiperf_state_tcp_t *conn = (lwiperf_state_tcp_t *)
arg;
359 LWIP_ASSERT(
"invalid conn", conn->conn_pcb == tpcb);
363 conn->poll_count = 0;
365 return lwiperf_tcp_client_send_more(conn);
370lwiperf_tcp_client_connected(
void *
arg,
struct tcp_pcb *tpcb,
err_t err)
372 lwiperf_state_tcp_t *conn = (lwiperf_state_tcp_t *)
arg;
373 LWIP_ASSERT(
"invalid conn", conn->conn_pcb == tpcb);
379 conn->poll_count = 0;
380 conn->time_started =
sys_now();
381 return lwiperf_tcp_client_send_more(conn);
389 void *report_arg, lwiperf_state_base_t *related_master_state, lwiperf_state_tcp_t **new_conn)
392 lwiperf_state_tcp_t *client_conn;
393 struct tcp_pcb *newpcb;
401 client_conn = (lwiperf_state_tcp_t *)LWIPERF_ALLOC(lwiperf_state_tcp_t);
402 if (client_conn ==
NULL) {
406 if (newpcb ==
NULL) {
407 LWIPERF_FREE(lwiperf_state_tcp_t, client_conn);
410 memset(client_conn, 0,
sizeof(lwiperf_state_tcp_t));
411 client_conn->base.tcp = 1;
412 client_conn->base.related_master_state = related_master_state;
413 client_conn->conn_pcb = newpcb;
414 client_conn->time_started =
sys_now();
415 client_conn->report_fn = report_fn;
416 client_conn->report_arg = report_arg;
417 client_conn->next_num = 4;
418 client_conn->bytes_transferred = 0;
420 client_conn->have_settings_buf = 1;
422 tcp_arg(newpcb, client_conn);
423 tcp_sent(newpcb, lwiperf_tcp_client_sent);
424 tcp_poll(newpcb, lwiperf_tcp_poll, 2U);
425 tcp_err(newpcb, lwiperf_tcp_err);
429 err =
tcp_connect(newpcb, &remote_addr, remote_port, lwiperf_tcp_client_connected);
434 lwiperf_list_add(&client_conn->base);
435 *new_conn = client_conn;
440lwiperf_tx_start_passive(lwiperf_state_tcp_t *conn)
443 lwiperf_state_tcp_t *new_conn =
NULL;
446 ret = lwiperf_tx_start_impl(&conn->conn_pcb->remote_ip, remote_port, &conn->settings, conn->report_fn, conn->report_arg,
447 conn->base.related_master_state, &new_conn);
450 new_conn->settings.flags = 0;
463 lwiperf_state_tcp_t *conn = (lwiperf_state_tcp_t *)
arg;
465 LWIP_ASSERT(
"pcb mismatch", conn->conn_pcb == tpcb);
474 if (conn->settings.flags &
PP_HTONL(LWIPERF_FLAGS_ANSWER_TEST)) {
475 if ((conn->settings.flags &
PP_HTONL(LWIPERF_FLAGS_ANSWER_NOW)) == 0) {
477 lwiperf_tx_start_passive(conn);
485 conn->poll_count = 0;
487 if ((!conn->have_settings_buf) || ((conn->bytes_transferred - 24) % (1024 * 128) == 0)) {
489 if (
p->tot_len <
sizeof(lwiperf_settings_t)) {
494 if (!conn->have_settings_buf) {
495 if (
pbuf_copy_partial(
p, &conn->settings,
sizeof(lwiperf_settings_t), 0) !=
sizeof(lwiperf_settings_t)) {
500 conn->have_settings_buf = 1;
501 if (conn->settings.flags &
PP_HTONL(LWIPERF_FLAGS_ANSWER_TEST)) {
502 if (conn->settings.flags &
PP_HTONL(LWIPERF_FLAGS_ANSWER_NOW)) {
504 err_t err2 = lwiperf_tx_start_passive(conn);
513 if (conn->settings.flags &
PP_HTONL(LWIPERF_FLAGS_ANSWER_TEST)) {
514 if (
pbuf_memcmp(
p, 0, &conn->settings,
sizeof(lwiperf_settings_t)) != 0) {
521 conn->bytes_transferred +=
sizeof(lwiperf_settings_t);
522 if (conn->bytes_transferred <= 24) {
523 conn->time_started =
sys_now();
524 tcp_recved(tpcb,
p->tot_len);
530 LWIP_ASSERT(
"pbuf_remove_header failed", tmp == 0);
536#if LWIPERF_CHECK_RX_DATA
542 if (
num == conn->next_num) {
544 if (conn->next_num == 10) {
554 packet_idx +=
q->len;
556 LWIP_ASSERT(
"count mismatch", packet_idx ==
p->tot_len);
557 conn->bytes_transferred += packet_idx;
567 lwiperf_state_tcp_t *conn = (lwiperf_state_tcp_t *)
arg;
571 conn->conn_pcb =
NULL;
572 conn->server_pcb =
NULL;
579lwiperf_tcp_poll(
void *
arg,
struct tcp_pcb *tpcb)
581 lwiperf_state_tcp_t *conn = (lwiperf_state_tcp_t *)
arg;
582 LWIP_ASSERT(
"pcb mismatch", conn->conn_pcb == tpcb);
584 if (++conn->poll_count >= LWIPERF_TCP_MAX_IDLE_SEC) {
589 if (!conn->base.server) {
590 lwiperf_tcp_client_send_more(conn);
598lwiperf_tcp_accept(
void *
arg,
struct tcp_pcb *newpcb,
err_t err)
600 lwiperf_state_tcp_t *
s, *conn;
605 s = (lwiperf_state_tcp_t *)
arg;
609 if (
s->specific_remote) {
610 LWIP_ASSERT(
"s->base.related_master_state != NULL",
s->base.related_master_state !=
NULL);
611 if (!
ip_addr_eq(&newpcb->remote_ip, &
s->remote_addr)) {
616 LWIP_ASSERT(
"s->base.related_master_state == NULL",
s->base.related_master_state ==
NULL);
619 conn = (lwiperf_state_tcp_t *)LWIPERF_ALLOC(lwiperf_state_tcp_t);
623 memset(conn, 0,
sizeof(lwiperf_state_tcp_t));
625 conn->base.server = 1;
626 conn->base.related_master_state = &
s->base;
627 conn->conn_pcb = newpcb;
628 conn->time_started =
sys_now();
629 conn->report_fn =
s->report_fn;
630 conn->report_arg =
s->report_arg;
633 tcp_arg(newpcb, conn);
635 tcp_poll(newpcb, lwiperf_tcp_poll, 2U);
636 tcp_err(conn->conn_pcb, lwiperf_tcp_err);
638 if (
s->specific_remote) {
640 conn->base.related_master_state =
s->base.related_master_state;
642 if (!
s->client_tradeoff_mode || !lwiperf_list_find(
s->base.related_master_state)) {
648 lwiperf_list_add(&conn->base);
664 report_fn, report_arg);
682 err = lwiperf_start_tcp_server_impl(local_addr, local_port, report_fn, report_arg,
692 lwiperf_state_base_t *related_master_state, lwiperf_state_tcp_t **
state)
696 lwiperf_state_tcp_t *
s;
702 if (local_addr ==
NULL) {
706 s = (lwiperf_state_tcp_t *)LWIPERF_ALLOC(lwiperf_state_tcp_t);
710 memset(
s, 0,
sizeof(lwiperf_state_tcp_t));
713 s->base.related_master_state = related_master_state;
714 s->report_fn = report_fn;
715 s->report_arg = report_arg;
717 pcb = tcp_new_ip_type(LWIPERF_SERVER_IP_TYPE);
721 err = tcp_bind(pcb, local_addr, local_port);
725 s->server_pcb = tcp_listen_with_backlog(pcb, 1);
726 if (
s->server_pcb ==
NULL) {
730 LWIPERF_FREE(lwiperf_state_tcp_t,
s);
735 tcp_arg(
s->server_pcb,
s);
738 lwiperf_list_add(&
s->base);
754 report_fn, report_arg);
779 settings.flags =
htonl(LWIPERF_FLAGS_ANSWER_TEST | LWIPERF_FLAGS_ANSWER_NOW);
794 ret = lwiperf_tx_start_impl(remote_addr, remote_port, &
settings, report_fn, report_arg,
NULL, &
state);
801 report_fn, report_arg, (lwiperf_state_base_t *)
state, &
server);
808 server->specific_remote = 1;
813 server->client_tradeoff_mode = 1;
832 for (
i = lwiperf_all_connections;
i !=
NULL; ) {
833 if ((
i == lwiperf_session) || (
i->related_master_state == lwiperf_session)) {
839 LWIPERF_FREE(lwiperf_state_tcp_t,
dealloc);
struct mke2fs_defaults settings[]
STREAM tcp_recv(STREAM s, uint32 length)
RD_BOOL tcp_connect(char *server)
#define LWIP_ASSERT(message, assertion)
void dealloc(int i, int no_throw)
GLuint GLuint GLsizei GLenum type
GLdouble GLdouble GLdouble GLdouble q
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define LWIP_UNUSED_ARG(x)
#define LWIP_CONST_CAST(target_type, val)
#define LWIP_ASSERT_CORE_LOCKED()
u16_t pbuf_memcmp(const struct pbuf *p, u16_t offset, const void *s2, u16_t n)
u8_t pbuf_free(struct pbuf *p)
u16_t pbuf_copy_partial(const struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
#define ip_addr_eq(addr1, addr2)
#define ip_addr_copy(dest, src)
#define IP_GET_TYPE(ipaddr)
void * lwiperf_start_tcp_client(const ip_addr_t *remote_addr, u16_t remote_port, enum lwiperf_client_type type, lwiperf_report_fn report_fn, void *report_arg)
void(* lwiperf_report_fn)(void *arg, enum lwiperf_report_type report_type, const ip_addr_t *local_addr, u16_t local_port, const ip_addr_t *remote_addr, u16_t remote_port, u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec)
void * lwiperf_start_tcp_server(const ip_addr_t *local_addr, u16_t local_port, lwiperf_report_fn report_fn, void *report_arg)
void * lwiperf_start_tcp_client_default(const ip_addr_t *remote_addr, lwiperf_report_fn report_fn, void *report_arg)
#define LWIPERF_TCP_PORT_DEFAULT
@ LWIPERF_TCP_ABORTED_LOCAL_TXERROR
@ LWIPERF_TCP_DONE_CLIENT
@ LWIPERF_TCP_DONE_SERVER
@ LWIPERF_TCP_ABORTED_LOCAL
@ LWIPERF_TCP_ABORTED_LOCAL_DATAERROR
@ LWIPERF_TCP_ABORTED_REMOTE
void lwiperf_abort(void *lwiperf_session)
void * lwiperf_start_tcp_server_default(lwiperf_report_fn report_fn, void *report_arg)
#define memcpy(s1, s2, n)
u8_t pbuf_remove_header(struct pbuf *p, size_t header_size_decrement)
static unsigned __int64 next
void tcp_close(struct sock *sk, long timeout)
struct sock * tcp_accept(struct sock *sk, int flags, int *err)
unsigned int tcp_poll(struct file *file, struct socket *sock, struct poll_table_struct *wait)
static rfbScreenInfoPtr server