If you want to send and receive on the same socket from two different threads, 
you’ll need to enable LWIP_NETCONN_FULLDUPLEX in opt.h (by default it’s not 
supported and feature is in alpha state):

/** LWIP_NETCONN_FULLDUPLEX==1: Enable code that allows reading from one thread,
 * writing from a 2nd thread and closing from a 3rd thread at the same time.
 * ATTENTION: This is currently really alpha! Some requirements:
 * - LWIP_NETCONN_SEM_PER_THREAD==1 is required to use one socket/netconn from
 *   multiple threads at once
 * - sys_mbox_free() has to unblock receive tasks waiting on recvmbox/acceptmbox
 *   and prevent a task pending on this during/after deletion
 */
#if !defined LWIP_NETCONN_FULLDUPLEX || defined __DOXYGEN__
#define LWIP_NETCONN_FULLDUPLEX         0
#endif

Joel

> On Jan 25, 2017, at 1:02 AM, Neerav Patel <neeravpa...@hotmail.com> wrote:
> 
> Hi,
> 
> I read that same statement after I had posted and so I created another system 
> thread (been debugging the whole day):
> 
> sys_thread_new("handle_thread", handle_thread, NULL, 400, 3);
> 
> and tried to send from it, and it also hung in the same way, seems to not 
> return from a semaphore call deep in the bowls of lwip, still digging further 
> into it.
> 
> Maybe this will do the same and call back from the tcpipthread.  
> 
> How would you propose structuring the code, I want one thread to receive 
> packets and another to send out?  Is creating a system thread the right way 
> to go?  Why would I be hanging with the code below?
> 
> Thanks for all the help!
> 
> void
> handle_thread( )
> {
>       while ( 1 )
>       {
>             if ( send_actual_pkt ) 
>             {
>                   send_actual_pkt = 0;
>                   uint8_t pkt[576];
>                   // ... populate the pkt
>                  uint16_t len = generate_pkt();
>                  if ( lwip_sendto( s, pkt, len, 0, (struct sockaddr *)&from, 
> sizeof(from) ) != len )   <---- hanging here!!!!
>                  {
>                        uart_printf( "Didnt send correctly %x\n", len );
>                  }
>             }
>        }
> }
> 
> 
> while( 1 )
>    {
>       if ( (lwip_recvfrom(s, raw_buf, sizeof(raw_buf), 0, (struct 
> sockaddr*)&from, (socklen_t*)&fromlen)) > 0 )
>       {
>                   send_actual_pkt = 1;
>       }
>    }
> 
> 
> 
> From: lwip-users <lwip-users-bounces+neeravpatel=hotmail....@nongnu.org 
> <mailto:lwip-users-bounces+neeravpatel=hotmail....@nongnu.org>> on behalf of 
> Dirk Ziegelmeier <d...@ziegelmeier.net <mailto:d...@ziegelmeier.net>>
> Sent: January 25, 2017 6:48 AM
> To: Mailing list for lwIP users
> Subject: Re: [lwip-users] lwip_sendto hanging with lwip 2.0
>  
> Calling sys_timeout() results in send_actual_pkt being called back from TCPIP 
> thread. You must not call sequencial style functions from TCPIP thread.
> 
> http://www.nongnu.org/lwip/2_0_0/group__sequential__api.html 
> <http://www.nongnu.org/lwip/2_0_0/group__sequential__api.html> says: "More 
> overhead, but can be called from any thread except TCPIP thread."
> lwIP: Sequential-style APIs - nongnu.org 
> <http://www.nongnu.org/lwip/2_0_0/group__sequential__api.html>
> www.nongnu.org <http://www.nongnu.org/>
> Detailed Description. Sequential-style APIs, blocking functions. More 
> overhead, but can be called from any thread except TCPIP thread.
> 
> 
> 
> Dirk
> 
> _______________________________________________
> lwip-users mailing list
> lwip-users@nongnu.org <mailto:lwip-users@nongnu.org>
> https://lists.nongnu.org/mailman/listinfo/lwip-users 
> <https://lists.nongnu.org/mailman/listinfo/lwip-users>
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to