Cojumos 发表于 2012-8-27 17:17:13

简单的RTT的UDP通信,接收一定的数据量就死机??

本帖最后由 Cojumos 于 2012-8-27 17:18 编辑

这是application的程序

int rt_application_init()
{
        rt_thread_t init_thread;
        /****************创建基础线程   *****************************/
        init_thread = rt_thread_create(        "init",
                                rt_init_thread_entry,
                                      RT_NULL,
                                2048, 8, 20);

        /* 开启线程 */
        if (init_thread != RT_NULL)
                rt_thread_startup(init_thread);
}


这是线程的程序
void rt_init_thread_entry(void* parameter)
{

/* LwIP Initialization */
#ifdef RT_USING_LWIP                                                //如果在rtconfig()定义,则使用该驱动
        {
                extern void lwip_sys_init(void);
                extern void        websrv();

                /* register ethernetif device */
                eth_system_device_init();

                rt_hw_enc28j60_init();
                rt_device_init_all();

                /* init lwip system */
                lwip_sys_init();                                         //以太网驱动初始化,系统在此处设置IP地址
                rt_kprintf("TCP/IP initialized!\n");
                websrv();                                                //TCP/IP服务函数,在此添加用户程序
        }
}


websrv

/* 线程入口 */
void lw_thread(void* paramter)
{
        struct netconn *conn;

        struct netbuf *buf_new;
        struct netbuf *inbuf;
        struct ip_addr addr;
        char *rq;
        rt_uint16_t len,_len;
        unsigned short *port;


        /*建立一个新的UDP连接句柄 */
        conn = netconn_new(NETCONN_UDP);

        /* 设置远程主机的IP地址,执行这个操作后,addr.addr的值为0x0100000a */
        addr.addr = htonl(0xc0A80105);                //192.168.1.5
        /* 连接远程主机 */
        netconn_connect(conn, &addr, 8080);

        buf_new = netbuf_new();

        while(1)
        {
                /*从这个连接读取数据到inbuf,我们假定在这个netbuf中包含完整的请求 */
                inbuf = netconn_recv(conn);

                /*获取指向netbuf中第一个数据片断的指针,在这个数据片段里我们希望包含这个请求 */
                netbuf_data(inbuf, (void**)&rq, &len);

                _len = netbuf_len(inbuf);         //获取数据包的长度
                netbuf_ref(buf_new, rq , _len);//复制上位机发过来的数据包
                netconn_send(conn,buf_new );//发送数据            

                rt_thread_delay(1);
        }
}

就是通过网络调试助手发数据给远程机,远程机返回一样的数据



于是让调试助手循环发送,但是发送到一定数量的Byte,远程机就没有返回数据。到底什么原因??
这是我测试的数据表

测试    每次发送   死机时接收   发送      发送
次数    字节数   数据总数   周期      次数
      (Byte)   (Byte)    (ms)

1        20        7140        1       
2        20        7140        2       
3        20        7140        5       
4        20        7140        10       
5        20        7140        20        357
6        20        7140        40       
7        20        7140        80       
8        20        7120        100       
9        20        7140         100       
10        20        7140         100       

11        19        6783        1       
12        19        6783        2       
13        19        6783        5       
14        19        6783        10       
15        19        6783        20       
16        19        6783        40        357
17        19        6783        80       
18        19        6783        100       
19        19        6783        10       
20        19        6783        10       

21        10        3670        1       
22        10        3670        1       
23        10        3670        2       
24        10        3670        5        367
25        10        3670        10       
26        10        3670        20       
27        10        3670        40       
28        10        3670        80       
29        10        3670        100       
30        10        3670        5       

31        5        1835        1       
32        5        1835        1       
33        5        1835        2        367
34        5        1835        10       
35        5        1835        100       

36        2        734        1       
37        2        734        1       
38        2        734        5        367
39        2        734        40       
40        2        734        100       

41        1        367        1       
42        1        367        1       
43        1        367        10        367
44        1        367        40       
45        1        367        100       

46        40        12440        1       
47        40        12440        1       
48        40        12440        10        311
49        40        12440        40       
50        40        12440        100       

51        100        22400        1       
52        100        22400        1       
53        100        22400        10        224
54        100        22400        40       
55        100        22400        100       

56        1000        43000        1       
57        1000        43000        1       
58        1000        43000        10        43
59        1000        43000        40       
60        1000        43000        100       


从表中得出,与发送周期大小无关,但是和每次发送的数据包长度和发送的次数有关系???
是不是要定时清理接收缓冲区??

Cojumos 发表于 2012-8-28 22:47:46

发现问题,没有释放接收的缓冲区,使用netconn_recv();后必须释放空间调用netbuf_delete();

sunhaoqin 发表于 2013-3-18 07:51:26

mark......................

jacky_shen 发表于 2013-3-21 14:42:04

留下标记。

hwdpaley 发表于 2013-8-22 11:41:02

RTT确实有许多要认真测试的地方

dzf050727 发表于 2014-3-11 10:08:59

mark,以后会用到,谢谢
页: [1]
查看完整版本: 简单的RTT的UDP通信,接收一定的数据量就死机??