[En-Nut-Discussion] NutTcpAccept blocks the tread

Harald Kipp harald.kipp at egnite.de
Fri Oct 23 11:05:09 CEST 2009


Hi Nathan,

Nathan Moore wrote:
> My second idea was to have the wakeup of "this thread" happen before
> changing the state of the socket to closed.
> Then when "this thread" is run code within NutTcpAccept
> (NutTcpPassiveOpenEvent, actually) will:
>   1. examine the state of the socket and decide if this is strictly a
> timeout.
>      (note:  if the timeout happens at the same time as an incoming SYN this
> would give preference to the SYN)
>   2. If it is strictly timeout it would asyncronously change the socket's
> state to closed and return a value to let the
>       caller know that a timeout has happened.
> This way if "this thread" doesn't sleep before it calls NutTcpAccept again
> there can be no moment where a network
> interface's RX thread is running while the socket is not listening.

Considered, that NutTcpPassiveOpenEvent had been changed following your
suggestion, the application will use the following pseudo code:

for (;;) {
  CreateSocket();
  SocketOption(Set read timeout);
  while (NutTcpAccept()) {
    /* Timout, do something else,
    ** but do not sleep. */
  }
  /* Handle the connection. */
  ...
  /* Finally */
  DestroySocket();
}

Is that what you meant?

Harald



More information about the En-Nut-Discussion mailing list