lwip-devel
[Top][All Lists]
Advanced

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

Re: [lwip-devel] Closing connections with rawapi


From: Sergio R. Caprile
Subject: Re: [lwip-devel] Closing connections with rawapi
Date: Fri, 02 May 2014 20:49:18 -0300
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

On 2/05/14 01:00, Per Knytt wrote:

> 1. It is forbidden to call tcp_abort() on a pcb that tcp_connect() has
> failed on.

Well, the SMTP code calls tcp_close() on failure.

>     This would make the API more cumbersome to use since if tcp_connect()
> fails,
>     for example because there's no free memory, then tcp_close() can fail
> for the same
>     reason. If we can't call tcp_abort() in that situation the application
> needs to save state
>     to be able to retry tcp_close() later until it succeeds. This is
> cumbersome in an
>     environment that doesn't support blocking operations.

The httpserver_raw code solves this by periodically calling tcp_close()
again via tcp_poll() if closing returns an error. AFAIK, tcp_poll() is
there to solve this issues:

  err = tcp_close(pcb);
  if (err != ERR_OK) {
    LWIP_DEBUGF(HTTPD_DEBUG, ("Error %d closing %p\n", err, (void*)pcb));
    /* error closing, try again later in poll */
    tcp_poll(pcb, http_poll, HTTPD_POLL_INTERVAL);
  }

HOWEVER, since tcp_close() calls tcp_rst() and this one calls
pbuf_alloc(), and has no return value, on low-memory conditions the RST
might not be sent and this go unnoticed.

The way the SMTP code might handle this is a bit more involved and I
don't see it right away, since it does not check for possible
tcp_close() errors (and is a state machine anyway)

> 2. It is forbidden to call tcp_connect() on a pcb on which tcp_bind() has
> been called.

Regarding the 'preferred solution', my comment in this case (as a user):
Well, I wouldn't do that since 'bind' means 'listen' and 'connect' means
'call'.
Since this is a 'light-weight' stack, I understand I'm responsible of my
own calls, and have no need for the stack to prevent me for making mistakes.

> 3. tcp_abort() should check if the pcb is bound and in that case remove it
> from tcp_bound_pcbs.

I guess you are trying to save a pcb and reusing it for binds and
connects... am I right ?

Regards




reply via email to

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