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

 

 

 

 

 

_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to