MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / tcpecho_entry

Function tcpecho_entry

examples/test/net_test.c:138–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136#define TCP_ECHO_PORT 7
137rt_thread_t tcpecho_tid = RT_NULL;
138void tcpecho_entry(void *parameter)
139{
140 struct netconn *conn, *newconn;
141 err_t err;
142
143 /* Create a new connection identifier. */
144 conn = netconn_new(NETCONN_TCP);
145 if(conn == NULL)
146 {
147 rt_kprintf("no memory error\n");
148 return;
149 }
150
151 /* Bind connection to well known port number 7. */
152 netconn_bind(conn, NULL, TCP_ECHO_PORT);
153
154 /* Tell connection to go into listening mode. */
155 netconn_listen(conn);
156
157 while(1)
158 {
159 /* Grab new connection. */
160#if LWIP_VERSION_MINOR==3U
161 newconn = netconn_accept(conn);
162 if(newconn != NULL)
163#else
164 err = netconn_accept(conn, &newconn);
165 if(err == ERR_OK)
166#endif
167 /* Process the new connection. */
168 {
169 struct netbuf *buf;
170 void *data;
171 u16_t len;
172#if LWIP_VERSION_MINOR==3U
173 while((buf = netconn_recv(newconn)) != NULL)
174#else
175 while((err = netconn_recv(newconn, &buf)) == ERR_OK)
176#endif
177 {
178 do
179 {
180 netbuf_data(buf, &data, &len);
181 err = netconn_write(newconn, data, len, NETCONN_COPY);
182 if(err != ERR_OK)
183 {
184 break;
185 }
186 }while(netbuf_next(buf) >= 0);
187
188 netbuf_delete(buf);
189 }
190 /* Close connection and discard connection identifier. */
191 netconn_delete(newconn);
192 }
193 }
194
195 netconn_delete(conn);

Callers

nothing calls this directly

Calls 8

rt_kprintfFunction · 0.85
netconn_bindFunction · 0.50
netconn_acceptFunction · 0.50
netconn_recvFunction · 0.50
netbuf_dataFunction · 0.50
netbuf_nextFunction · 0.50
netbuf_deleteFunction · 0.50
netconn_deleteFunction · 0.50

Tested by

no test coverage detected