One active TCP connection at a time

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

One active TCP connection at a time

Jeffrey Nichols
Hi,

I'm trying to figure out the best way to have only one incoming TCP
connection active at a time.

I inherited some code that calls tcp_close() on the listening pcb inside
the tcp_accept callback, and creates a new listener later when the
active connection is closed. I'm not certain that this is the best way
to do this, and suspect there may be edge cases that will be missed. The
listener has to set the SOF_REUSEADDR option whenever it gets created to
make everything work.

I've been trying to familiarize myself with lwip and looking to see if
there's a supported way to achieve this functionality. Some other
options that occur to me are using TCP_LISTEN_BACKLOG or calling
tcp_abort on all of the new pcbs inside the tcp_accept callback.

Does anyone have any advice for the best way to achieve only one active
connection at a time?

Thanks,
Jeff

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: One active TCP connection at a time

Jeffrey Nichols
Replying to myself here. This did indeed cause issues.

Calling tcp_close() on the listening pcb inside the tcp_accept callback
I occasionally get a deadlock inside tcp_remove_listener(), where the
linked list is circular: pcb->next is equal to pcb.

Anyone have any ideas for how to debug/fix this?

Thanks,
Jeff

On 8/25/2019 10:28 AM, Jeffrey Nichols wrote:

> Hi,
>
> I'm trying to figure out the best way to have only one incoming TCP
> connection active at a time.
>
> I inherited some code that calls tcp_close() on the listening pcb
> inside the tcp_accept callback, and creates a new listener later when
> the active connection is closed. I'm not certain that this is the best
> way to do this, and suspect there may be edge cases that will be
> missed. The listener has to set the SOF_REUSEADDR option whenever it
> gets created to make everything work.
>
> I've been trying to familiarize myself with lwip and looking to see if
> there's a supported way to achieve this functionality. Some other
> options that occur to me are using TCP_LISTEN_BACKLOG or calling
> tcp_abort on all of the new pcbs inside the tcp_accept callback.
>
> Does anyone have any advice for the best way to achieve only one
> active connection at a time?
>
> Thanks,
> Jeff
>
> _______________________________________________
> lwip-users mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/lwip-users


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: One active TCP connection at a time

goldsimon@gmx.de
Am 31.10.2019 um 20:59 schrieb Jeffrey Nichols:
> Replying to myself here. This did indeed cause issues.
>
> Calling tcp_close() on the listening pcb inside the tcp_accept callback
> I occasionally get a deadlock inside tcp_remove_listener(), where the
> linked list is circular: pcb->next is equal to pcb.
>
> Anyone have any ideas for how to debug/fix this?

That should not happen. When getting such circular lists, most probably
a threading issue is the cause.

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: One active TCP connection at a time

Jeffrey Nichols
Hi Simon,

I think that the issue was that I was calling tcp_close() in tcp_err
callback. At least I haven't seen it since I fixed that.

I had a similar deadlocking issue that I tracked down to running out of
tcp pcbs, which I fixed by increasing MEMP_NUM_TCP_PCB from 5 to 30.

Everything seems to be stable now.

Thanks,
Jeff

On 11/4/2019 3:30 PM, [hidden email] wrote:

> Am 31.10.2019 um 20:59 schrieb Jeffrey Nichols:
>> Replying to myself here. This did indeed cause issues.
>>
>> Calling tcp_close() on the listening pcb inside the tcp_accept callback
>> I occasionally get a deadlock inside tcp_remove_listener(), where the
>> linked list is circular: pcb->next is equal to pcb.
>>
>> Anyone have any ideas for how to debug/fix this?
>
> That should not happen. When getting such circular lists, most probably
> a threading issue is the cause.
>
> Regards,
> Simon
>
> _______________________________________________
> lwip-users mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/lwip-users


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users