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: pek
Subject: Re: [lwip-devel] Closing connections with rawapi
Date: Mon, 05 May 2014 09:36:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

"Sergio R. Caprile" <address@hidden> writes:

> 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);
>   }

Right, this is what I mean by "more cumbersome" since the application
may need to store the pcb separately and retry tcp_close() in a poll
loop or callback.

>> 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.

That's fine as long as the documentation states that this is the case.
Wether the extra code to have tcp_abort() handle bound sockets is worth
it or not is arguable, I personally think a clean API is worth more
since the code overhead should be small but I'm not religious about it.

>> 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 ?

The tcp_bind() call that caused this was not necessary in the actual
application so I've fixed _my_ issue by just removing it. Now I'm just
trying to prevent someone else from having the same problem :)

Sincerely
Per Knytt




reply via email to

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