add version checking
This commit is contained in:
parent
a8804d3503
commit
c1d0db700c
|
@ -5,6 +5,8 @@
|
|||
#include <finsh.h>
|
||||
#include <lwip/api.h>
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/init.h>
|
||||
|
||||
/*
|
||||
* UDP echo server
|
||||
*/
|
||||
|
@ -23,7 +25,11 @@ void udpecho_entry(void *parameter)
|
|||
while(1)
|
||||
{
|
||||
/* received data to buffer */
|
||||
#if LWIP_VERSION_MINOR==3U
|
||||
buf = netconn_recv(conn);
|
||||
#else
|
||||
netconn_recv(conn, &buf);
|
||||
#endif
|
||||
|
||||
addr = netbuf_fromaddr(buf);
|
||||
port = netbuf_fromport(buf);
|
||||
|
@ -32,7 +38,12 @@ void udpecho_entry(void *parameter)
|
|||
netconn_connect(conn, addr, port);
|
||||
|
||||
/* reset address, and send to client */
|
||||
#if LWIP_VERSION_MINOR==3U
|
||||
buf->addr = RT_NULL;
|
||||
#else
|
||||
buf->addr = *IP_ADDR_ANY;
|
||||
#endif
|
||||
|
||||
netconn_send(conn, buf);
|
||||
|
||||
/* release buffer */
|
||||
|
@ -122,15 +133,23 @@ void tcpecho_entry(void *parameter)
|
|||
while(1)
|
||||
{
|
||||
/* Grab new connection. */
|
||||
#if LWIP_VERSION_MINOR==3U
|
||||
newconn = netconn_accept(conn);
|
||||
if(newconn != NULL)
|
||||
#else
|
||||
err = netconn_accept(conn, &newconn);
|
||||
/* Process the new connection. */
|
||||
if(err == ERR_OK)
|
||||
#endif
|
||||
/* Process the new connection. */
|
||||
{
|
||||
struct netbuf *buf;
|
||||
void *data;
|
||||
u16_t len;
|
||||
|
||||
while((err = netconn_recv(newconn, buf)) == ERR_OK)
|
||||
#if LWIP_VERSION_MINOR==3U
|
||||
while((buf = netconn_recv(newconn)) != NULL)
|
||||
#else
|
||||
while((err = netconn_recv(newconn, &buf)) == ERR_OK)
|
||||
#endif
|
||||
{
|
||||
do
|
||||
{
|
||||
|
@ -214,9 +233,8 @@ void tcpecho_socket_entry(void *parameter)
|
|||
bytes_received = recv(connected,recv_data, TCP_SOCKET_BUFFER_SIZE, 0);
|
||||
if (bytes_received <= 0)
|
||||
{
|
||||
rt_kprintf("close client connection, errno: %d, socket error: %d\n",
|
||||
rt_get_errno(),
|
||||
lwip_get_error());
|
||||
rt_kprintf("close client connection, errno: %d\n",
|
||||
rt_get_errno());
|
||||
/* connection closed. */
|
||||
lwip_close(connected);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue