lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] multithread netconn / udp echo on two differentthreads


From: Martin Persich
Subject: Re: [lwip-users] multithread netconn / udp echo on two differentthreads and ports
Date: Tue, 13 Apr 2010 23:13:51 +0200

LwIP netconn API is thread safety, I think. I have many waiting UDP / TCP connections in separated thread and without problem.
Do you have this sample "echo server" from
http://cvs.savannah.gnu.org/viewvc/contrib/apps/udpecho/udpecho.c?revision=1.7&root=lwip&view=markup 
This example required a quite big stack size ( cca > 4200 Bytes for each task ) by my mind.
Do you have sufficient stack size ?
Martin Persich
----- Original Message -----
Sent: Tuesday, April 13, 2010 9:53 PM
Subject: [lwip-users] multithread netconn / udp echo on two differentthreads and ports

I have a general question about the thread safety for the actual lwip version (download from cvs 9.4.2010).

Is the netconn API thread safe or have the same problems as socket api?

 

I create two tasks – each runs an udp echo server on an own netconn struct with different ports listening.

If I send udp packets to only one port I get the correct feedback – if I send packets to both ports I get the correct feedback from the higher prior thread but the lower prior thread does

sometimes not answer.

 

Code for echo:

 

   static struct netconn *conn;

   static struct netbuf *buf;

   static ip_addr_t *addr;

   static ip_addr_t destip;

   static unsigned short port;

   static char buffer[4096];

   static err_t ret;

 

netconn init:

 

   conn = netconn_new(NETCONN_UDP);

   netconn_bind(conn, NULL, 7001);            // 7002 for thread 2

 

endless thread loop:

 

      netconn_recv(conn,&buf);

      addr = netbuf_fromaddr(buf);

      destip = *addr;                                             

      port = netbuf_fromport(buf);

      netbuf_copy(buf, buffer, buf->p->tot_len);

      buffer[buf->p->tot_len] = '\0';                        // Do something with – e.g. print the test string

      ret=netconn_sendto(conn,buf,&destip,port);

      netbuf_delete(buf);

 

 

Second problem: If I use addr instead of copying the ip to destip and call netconn_sendto(conn,buf,addr,port);   I only catch an gratuitous arp packet with my on ip on wireshark

Same problems if I connect and use netconn_send instead the above code:

 

      netconn_recv(conn,&buf);

      addr = netbuf_fromaddr(buf);

      port = netbuf_fromport(buf);

      ret=netconn_connect(conn, addr, port);

      netbuf_copy(buf, buffer, buf->p->tot_len);

      buffer[buf->p->tot_len] = '\0';

      netconn_send(conn, buf);

      netbuf_delete(buf);

 

here helps:

 

      netconn_recv(conn,&buf);

      addr = netbuf_fromaddr(buf);

      destip = *addr;

      port = netbuf_fromport(buf);

      ret=netconn_connect(conn, &destip, port);

      netbuf_copy(buf, buffer, buf->p->tot_len);

      buffer[buf->p->tot_len] = '\0';

 

      buf->addr=&destip;

      buf->port=port;

 

      netconn_send(conn, buf);

      netbuf_delete(buf);

 

 

 

Many thanks for help

Robert

 

 

 

 

 


reply via email to

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