lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] new at lwip, running test on windows using PPP


From: zulu4711
Subject: [lwip-users] new at lwip, running test on windows using PPP
Date: Sun, 26 Nov 2017 11:13:29 -0700 (MST)

I'm beginning to look at lwip and the first task is to get something running
on a windows system (to try and learn how lwip is working). Target will be
to have it running in an embedded system (Cortex M4, Keil development
tools).

I'm using lwip 2.0.2 and contrib 2.0.1, running in Visual Studio in windows.
I have been experimenting some, I do have PPP working (LTE module) and I can
send and receive data over a socket (using socket.c) for hours. 
I know that most people that have had problems was because of the threading
model, and it might also be that this is what is haunting me, so be gentle
with me ;)
I see a protection faul once in a while, sometimes it can run for hours
(sending and receiving a small packet every second) even a day. And the the
null pointer sticks its face up. I have taken a screendump from the code
once this happens (below).

I have taken most of the windows contrib code and added a thread that will
do the tx/rx of socket data.
The sio handling is done as the original code (main loop).

The thread I'm using looks like this, I wonder if I'm doing something
fundamentally wrong....


void thWorkerSocket(void* arg) {

        int tick=0, i=0, rxerror=0, sent_data, recv_data=0;
        char message[128];
        char rxbuf[128];
        int socket_fd;
        struct sockaddr_in sa,ra;
        int retry=0;
        int mynumber;
        void sleepy(int ms);

        while (netif_is_link_up(&ppp_netif)==0)       sleepy(1000);

        socket_fd = socket(PF_INET, SOCK_STREAM, 0);
        if ( socket_fd < 0 ) {
                printf("socket call failed");
                return;
        }
        
        
        memset(&sa, 0, sizeof(struct sockaddr_in));
        sa.sin_family = AF_INET;
        //sa.sin_addr.s_addr = ip4addr_ntoa(netif_ip4_addr(&ppp_netif)));//
inet_addr("127.0.0.0");
        sa.sin_addr.s_addr = INADDR_ANY;
        sa.sin_port = htons(0);


        /* Bind the TCP socket to the port SENDER_PORT_NUM and to the current
        * machines IP address (Its defined by SENDER_IP_ADDR). 
        * Once bind is successful for UDP sockets application can operate
        * on the socket descriptor for sending or receiving data.
        */
        if (bind(socket_fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) 
==
-1) {
                printf("Bind failed\n");
                close(socket_fd);
                return;
        }



        memset(&ra, 0, sizeof(struct sockaddr_in));
        ra.sin_family = AF_INET;
        ra.sin_addr.s_addr = inet_addr(SERVER_IP_ADDR);
        ra.sin_port = htons(SERVER_PORT_NUM);

        if(connect(socket_fd,(struct sockaddr_in*)&ra,sizeof(struct 
sockaddr_in)) <
0) {
                printf("connect failed \n");
                close(socket_fd);
                return;
        }

        insnumber++;
        mynumber=insnumber;

        while (1) {


                        tick++;
                        printf("Tock=%i\n", tick);

                        sprintf(message,"%i,CONNECT,%i\r", tick, mynumber);     
        
                        sent_data = send(socket_fd, message, strlen(message)+1, 
0);


                        if (sent_data < 0) {
                                printf("Send failed\n");
                                close(socket_fd);
                                socket_fd = socket(PF_INET, SOCK_STREAM, 0);
                                if ( socket_fd < 0 ) {
                                        printf("socket call failed");
                                        continue;
                                }
                                
                                
                                memset(&sa, 0, sizeof(struct sockaddr_in));
                                sa.sin_family = AF_INET;
                                sa.sin_addr.s_addr = INADDR_ANY;
                                sa.sin_port = htons(0);
                                if (bind(socket_fd, (struct sockaddr *)&sa, 
sizeof(struct sockaddr_in))
== -1) {
                                        printf("Bind failed\n");
                                        close(socket_fd);
                                        continue;
                                }

                                if(connect(socket_fd,(struct 
sockaddr_in*)&ra,sizeof(struct
sockaddr_in)) < 0) {
                                        printf("connect failed \n");
                                        close(socket_fd);
                                        sleepy(10000);
                                }
                        } else {
                                recv_data = recv(socket_fd, rxbuf, 
sizeof(rxbuf), 0);
                                if (recv <= 0) {
                                        rxerror++;
                                        printf("Socket::Receive timeout, rc=%i 
(timeout=%i)\n", i, rxerror);
                                        close(socket_fd);
                                        sleepy(10000);
                                } else {
                                        rxbuf[recv_data-1]=0;
                                        printf("Socket::Receive data [%s], 
length=%i, errors=%i\n", rxbuf,
recv_data, rxerror);
                                }
                        }
                sleepy(1000);
        }
}




<http://lwip.100.n7.nabble.com/file/t1962/Udklip.jpg> 



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]