Hardware/STM32

[FreeRTOS] lwip netconn 에서 동작 에러

Aspatom 2018. 5. 25. 02:57

- thread상에서 2개의 thread를 동시에 열고 netconn를 여러개 사용할수 없음

 -> 하나의 스레드에서만 하거나, opt.h 파일 내에서 설정을 변경하여 SYS_LIGHTWEIGHT_PROT를 0으로 두어 알아서 제어하면 됨


- client 단을 만들때에는 delete를 했을때 제대로 delete가 안되는 문제가 있을수 있음


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
static void tcpecho_thread(void *arg)
{
    struct netconn *conn, *newconn;
    err_t err, errWrite;
    LWIP_UNUSED_ARG(arg);
    /* Create a new connection identifier. */
    conn = netconn_new(NETCONN_TCP);
 
    if (conn!=NULL
    {  
        /* Bind connection to well known port number 25262. */
        err = netconn_bind(conn, NULL, RECV_PORT);
        if (err == ERR_OK) 
        {
            /* Tell connection to go into listening mode. */
            netconn_listen(conn);
 
            while (1
            {
                /* Grab new connection. */
                newconn = netconn_accept(conn);
                /* Process the new connection. */
                if(newconn) 
                {
                    struct netbuf *buf;
                    void *data;
                    u16_t len;
                    //LCD_LINE_Control(Line3, "Server Connected");
 
                    while((buf = netconn_recv(newconn)) != NULL
                    {
                        do 
                        {
                            netbuf_data(buf, &data, &len);
                            errWrite = netconn_write(newconn, data, len, NETCONN_COPY);
                        } while (netbuf_next(buf) >= 0);
                        netbuf_delete(buf);
                    }
                    /* Close connection and discard connection identifier. */
                    netconn_close(newconn);
                    netconn_delete(newconn);
                } 
            }
        } 
        else 
        {
            printf(" can not bind TCP netconn");
        }
    } 
    else 
    {
    printf("can not create TCP netconn");
    }
}
cs