| 136 | #define TCP_ECHO_PORT 7 |
| 137 | rt_thread_t tcpecho_tid = RT_NULL; |
| 138 | void 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); |
nothing calls this directly
no test coverage detected