On Wed, Jun 15, 2011 at 2:13 AM, wurzel<address@hidden> wrote:
My question is, can I call tcp_write from within a tcp_recv
callback? In this code, I've opened a pair of TCP pcbs and
each one's state struct has a "mate" field that points to
the other side's state struct to I can get its pcb.
I think that's a very good question indeed, because we give no
explicit guarantee in our documentation that this is guaranteed to
work, AFAIK. A function is called reentrant if it can be interrupted
and called again before previous calls complete execution. Now, as
there are global variables in the stack, we cannot easily guarantee
reentrancy, other than through code validation.
snderr = tcp_write(rs->mate->mypcb, q->payload, q->len,
By the strictest definition of "non-reentrant" this might not be
legal. On the other hand, this seems like a commonly-desired case,
so I'm hoping it is expected to work?
Yes, this should work. The tcp transmit code paths are cleanly
seperated from the receive code paths through data structures. We
should assume at the callback point the tcp state machine has those
structures in valid state, valid enough to call into tcp_write().