1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
102
103
104
105
109
110
111
/* ... */
#include "lwip/opt.h"
#if LWIP_NETCONN
#include "lwip/sys.h"
#include "lwip/api.h"
#define TCPECHO_THREAD_PRIO ( tskIDLE_PRIORITY + 4 )
static void tcpecho_thread(void *arg)
{
struct netconn *conn, *newconn;
err_t err, accept_err;
struct netbuf *buf;
void *data;
u16_t len;
LWIP_UNUSED_ARG(arg);
conn = netconn_new(NETCONN_TCP);
if (conn!=NULL)
{
err = netconn_bind(conn, NULL, 7);
if (err == ERR_OK)
{
netconn_listen(conn);
while (1)
{
accept_err = netconn_accept(conn, &newconn);
if (accept_err == ERR_OK)
{
while (netconn_recv(newconn, &buf) == ERR_OK)
{
do
{
netbuf_data(buf, &data, &len);
netconn_write(newconn, data, len, NETCONN_COPY);
...}
while (netbuf_next(buf) >= 0);
netbuf_delete(buf);
}while (netconn_recv(newconn, &buf) == ERR_OK) { ... }
netconn_close(newconn);
netconn_delete(newconn);
}if (accept_err == ERR_OK) { ... }
}while (1) { ... }
}if (err == ERR_OK) { ... }
else
{
netconn_delete(newconn);
}else { ... }
}if (conn!=NULL) { ... }
}{ ... }
void tcpecho_init(void)
{
sys_thread_new("tcpecho_thread", tcpecho_thread, NULL, DEFAULT_THREAD_STACKSIZE, TCPECHO_THREAD_PRIO);
}{ ... }
/* ... */
#endif