mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-28 03:47:11 +08:00
Update net_test.c
Fixed pointer check, indentation
This commit is contained in:
parent
f8a20ee433
commit
6e6dfb0003
@ -20,6 +20,11 @@ void udpecho_entry(void *parameter)
|
|||||||
unsigned short port;
|
unsigned short port;
|
||||||
|
|
||||||
conn = netconn_new(NETCONN_UDP);
|
conn = netconn_new(NETCONN_UDP);
|
||||||
|
if(conn == NULL)
|
||||||
|
{
|
||||||
|
rt_kprintf("no memory error\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
netconn_bind(conn, IP_ADDR_ANY, 7);
|
netconn_bind(conn, IP_ADDR_ANY, 7);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
@ -30,7 +35,10 @@ void udpecho_entry(void *parameter)
|
|||||||
#else
|
#else
|
||||||
netconn_recv(conn, &buf);
|
netconn_recv(conn, &buf);
|
||||||
#endif
|
#endif
|
||||||
|
if(buf == NULL)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
addr = netbuf_fromaddr(buf);
|
addr = netbuf_fromaddr(buf);
|
||||||
port = netbuf_fromport(buf);
|
port = netbuf_fromport(buf);
|
||||||
|
|
||||||
@ -49,6 +57,8 @@ void udpecho_entry(void *parameter)
|
|||||||
/* release buffer */
|
/* release buffer */
|
||||||
netbuf_delete(buf);
|
netbuf_delete(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
netconn_delete(conn);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* UDP socket echo server
|
* UDP socket echo server
|
||||||
@ -123,6 +133,11 @@ void tcpecho_entry(void *parameter)
|
|||||||
|
|
||||||
/* Create a new connection identifier. */
|
/* Create a new connection identifier. */
|
||||||
conn = netconn_new(NETCONN_TCP);
|
conn = netconn_new(NETCONN_TCP);
|
||||||
|
if(conn == NULL)
|
||||||
|
{
|
||||||
|
rt_kprintf("no memory error\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Bind connection to well known port number 7. */
|
/* Bind connection to well known port number 7. */
|
||||||
netconn_bind(conn, NULL, TCP_ECHO_PORT);
|
netconn_bind(conn, NULL, TCP_ECHO_PORT);
|
||||||
@ -155,15 +170,20 @@ void tcpecho_entry(void *parameter)
|
|||||||
{
|
{
|
||||||
netbuf_data(buf, &data, &len);
|
netbuf_data(buf, &data, &len);
|
||||||
err = netconn_write(newconn, data, len, NETCONN_COPY);
|
err = netconn_write(newconn, data, len, NETCONN_COPY);
|
||||||
if(err != ERR_OK){}
|
if(err != ERR_OK)
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
while(netbuf_next(buf) >= 0);
|
}while(netbuf_next(buf) >= 0);
|
||||||
|
|
||||||
netbuf_delete(buf);
|
netbuf_delete(buf);
|
||||||
}
|
}
|
||||||
/* Close connection and discard connection identifier. */
|
/* Close connection and discard connection identifier. */
|
||||||
netconn_delete(newconn);
|
netconn_delete(newconn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
netconn_delete(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -233,8 +253,7 @@ void tcpecho_socket_entry(void *parameter)
|
|||||||
bytes_received = recv(connected,recv_data, TCP_SOCKET_BUFFER_SIZE, 0);
|
bytes_received = recv(connected,recv_data, TCP_SOCKET_BUFFER_SIZE, 0);
|
||||||
if (bytes_received <= 0)
|
if (bytes_received <= 0)
|
||||||
{
|
{
|
||||||
rt_kprintf("close client connection, errno: %d\n",
|
rt_kprintf("close client connection, errno: %d\n", rt_get_errno());
|
||||||
rt_get_errno());
|
|
||||||
/* connection closed. */
|
/* connection closed. */
|
||||||
lwip_close(connected);
|
lwip_close(connected);
|
||||||
break;
|
break;
|
||||||
@ -251,7 +270,7 @@ _exit:
|
|||||||
if (sock != -1) lwip_close(sock);
|
if (sock != -1) lwip_close(sock);
|
||||||
rt_free(recv_data);
|
rt_free(recv_data);
|
||||||
|
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -265,36 +284,52 @@ void net_test(void)
|
|||||||
if (udpecho_tid == RT_NULL)
|
if (udpecho_tid == RT_NULL)
|
||||||
{
|
{
|
||||||
udpecho_tid = rt_thread_create("uecho",
|
udpecho_tid = rt_thread_create("uecho",
|
||||||
udpecho_entry, RT_NULL,
|
udpecho_entry,
|
||||||
512, RT_THREAD_PRIORITY_MAX/2, 5);
|
RT_NULL,
|
||||||
|
512,
|
||||||
|
RT_THREAD_PRIORITY_MAX/2, 5);
|
||||||
if (udpecho_tid != RT_NULL)
|
if (udpecho_tid != RT_NULL)
|
||||||
|
{
|
||||||
rt_thread_startup(udpecho_tid);
|
rt_thread_startup(udpecho_tid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (udpecho_socket_tid == RT_NULL)
|
if (udpecho_socket_tid == RT_NULL)
|
||||||
{
|
{
|
||||||
udpecho_socket_tid = rt_thread_create("uecho_s",
|
udpecho_socket_tid = rt_thread_create("uecho_s",
|
||||||
udpecho_socket_entry, RT_NULL,
|
udpecho_socket_entry,
|
||||||
512, RT_THREAD_PRIORITY_MAX/2 + 1, 5);
|
RT_NULL,
|
||||||
|
512,
|
||||||
|
RT_THREAD_PRIORITY_MAX/2 + 1, 5);
|
||||||
if (udpecho_socket_tid != RT_NULL)
|
if (udpecho_socket_tid != RT_NULL)
|
||||||
|
{
|
||||||
rt_thread_startup(udpecho_socket_tid);
|
rt_thread_startup(udpecho_socket_tid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tcpecho_tid == RT_NULL)
|
if (tcpecho_tid == RT_NULL)
|
||||||
{
|
{
|
||||||
tcpecho_tid = rt_thread_create("techo",
|
tcpecho_tid = rt_thread_create("techo",
|
||||||
tcpecho_entry, RT_NULL,
|
tcpecho_entry,
|
||||||
512, RT_THREAD_PRIORITY_MAX/2 + 2, 5);
|
RT_NULL,
|
||||||
|
512,
|
||||||
|
RT_THREAD_PRIORITY_MAX/2 + 2, 5);
|
||||||
if (tcpecho_tid != RT_NULL)
|
if (tcpecho_tid != RT_NULL)
|
||||||
|
{
|
||||||
rt_thread_startup(tcpecho_tid);
|
rt_thread_startup(tcpecho_tid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tcpecho_socket_tid == RT_NULL)
|
if (tcpecho_socket_tid == RT_NULL)
|
||||||
{
|
{
|
||||||
tcpecho_socket_tid = rt_thread_create("techo_s",
|
tcpecho_socket_tid = rt_thread_create("techo_s",
|
||||||
tcpecho_socket_entry, RT_NULL,
|
tcpecho_socket_entry,
|
||||||
512, RT_THREAD_PRIORITY_MAX/2 + 3, 5);
|
RT_NULL,
|
||||||
|
512,
|
||||||
|
RT_THREAD_PRIORITY_MAX/2 + 3, 5);
|
||||||
if (tcpecho_socket_tid != RT_NULL)
|
if (tcpecho_socket_tid != RT_NULL)
|
||||||
|
{
|
||||||
rt_thread_startup(tcpecho_socket_tid);
|
rt_thread_startup(tcpecho_socket_tid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FINSH_FUNCTION_EXPORT(net_test, network test);
|
FINSH_FUNCTION_EXPORT(net_test, network test);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user