[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Limiting the number of connections: Possible bug with M
From: |
address@hidden |
Subject: |
Re: [lwip-users] Limiting the number of connections: Possible bug with MEMP_NUM_TCP_PCB? |
Date: |
Thu, 3 Aug 2017 21:16:35 +0200 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
Tony wrote:
The aim is to only allow n open TCP connection at a time, and reject
all further connection requests. This worked reasonably well in 1.3.2,
but now fails in 2.0.2.
[..]
HOWEVER: this n+1 connection terminates the very 1st connection (takes
over the 1st PCB?).
Although it's strange it's like that, this is expected behaviour of
tcp_alloc(). I compared 2.0.2 to 1.3.2 and I don't really see a
difference though...
Anyway, the pcb limitation might not be the correct solution. A listen
backlog might better do what you want.
If you want to stay with your pcb limitation, try calling
"tcp_setprio(newpcb, TCP_PRIO_MAX);" after you allocate the first n
pcbs. That should prevent tcp_alloc from reusing them.
Now, if I leave all previous connections open and make a n+1
connection (the 6th connection in this example) I hit an exception
(the processor tries to access memory that does not exists and I hit
the exception handler in the MCU).
Now this indeed looks like a bug in your port, not in lwIP.
I narrowed down the origin of the fatal exception in tcp_alloc() to
the code following this comment:
/* zero out the whole pcb, so there is no need to initialize members
to zero */
The problem at that point seems to be that a struct tcp_pcb_listen
(that is still in use) is reused and overwritten as a struct tcp_pcb...
Ehrm, the pcb that is used there should *NOT* be a listen pcb. It comes
from the MEMP_TCP_PCB pool, so it's a standard pcb. Why do you think
it's a listen pcb which is still in use? This lets me think you have a
port problem...
Is there a way to simply "tell" LWIP to "refuse" further connections?
As I wrote above, give your other connections a higher prio so new
connections won't kill the existing ones.
Are there things that I might have missed that need to be changed in
my application, when going from 1.3.2 to 2.0.2?
None that I know of. If you find any, please let us know!
Cheers,
Simon