lwip-devel
[Top][All Lists]
Advanced

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

[lwip-devel] Preparing for LWIP_NETCONN_FULLDUPLEX, unclear what source


From: Benjamin Kalytta
Subject: [lwip-devel] Preparing for LWIP_NETCONN_FULLDUPLEX, unclear what source code comment means
Date: Thu, 23 Jan 2020 12:44:58 +0000

Hello,

I've a question concerning a source code comment in opt.h related to 
LWIP_NETCONN_FULLDUPLEX = 1

/** 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

What is not clear for me is the statement "sys_mbox_free() has to unblock 
receive tasks waiting on recvmbox/acceptmbox and prevent a task pending on this 
during/after deletion"

What does this actually mean, is there any example?

Take "lwip_recv_tcp" for an example. It calls "netconn_recv_tcp_pbuf_flags" 
which calls " netconn_recv_data_tcp" which calls " netconn_recv_data". This 
method returns either if new data is available or the connection has been 
closed. So in either case it should return in some point.

In that method NETCONN_MBOX_WAITING_INC is called first which atomatically 
increments "conn->mbox_threads_waiting" by one. After that " 
sys_arch_mbox_fetch" waits for an message in that mailbox and blocks as long as 
there is no new message/data. After message receival NETCONN_MBOX_WAITING_DEC 
is called to decrement "conn->mbox_threads_waiting" by one again.

After that it is checked if waiting was canceled by another thread:

  if (conn->flags & NETCONN_FLAG_MBOXINVALID) {
    if (lwip_netconn_is_deallocated_msg(buf)) {
      /* the netconn has been closed from another thread */
      API_MSG_VAR_FREE_ACCEPT(msg);
      return ERR_CONN;
    }
  }

So under what circumstances it is required to "unblock receive tasks waiting on 
recvmbox/acceptmbox" and how could "sys_mbox_free" know who is using that mail 
box? Can some one shed light into this topic and how to correctly implement it?

With Kind Regards,
Benjamin Kalytta



reply via email to

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