lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] multithread netconn / udp echo on two different threads and


From: Robert Braatz
Subject: [lwip-users] multithread netconn / udp echo on two different threads and ports
Date: Tue, 13 Apr 2010 21:53:56 +0200

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]