A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
Diff: tcp/tcb.c
- Revision:
- 78:9d8fc88df405
- Parent:
- 74:c3756bfa960e
- Child:
- 79:f50e02fb5c94
diff -r 6cb7d92c37f3 -r 9d8fc88df405 tcp/tcb.c --- a/tcp/tcb.c Wed Oct 31 20:22:01 2018 +0000 +++ b/tcp/tcb.c Mon Nov 05 19:27:19 2018 +0000 @@ -19,12 +19,15 @@ isn += 100000; //Gives each tcb 100,000 packets and won't repeat before 42,940 tcbs. return isn; } -struct tcb* TcbGetExisting(uint16_t port) +struct tcb* TcbGetExisting(int ipType, int remArIndex, uint16_t port) { for (int i = 0; i < TCB_COUNT; i++) { struct tcb* pTcb = tcbs + i; - if (pTcb->state != TCB_EMPTY && pTcb->remPort == port) return pTcb; + if (pTcb->state && + pTcb->ipType == ipType && + pTcb->remArIndex == remArIndex && + pTcb->remPort == port) return pTcb; } return NULL; } @@ -37,12 +40,15 @@ } return NULL; } -struct tcb* TcbGetNext() +void TcbGetNext(struct tcb** ppTcb) { - static struct tcb* pTcbNext = tcbs; - struct tcb* pTcbThis = pTcbNext++; - if (pTcbNext >= tcbs + TCB_COUNT) pTcbNext = tcbs; - return pTcbThis; + if (!*ppTcb) //Initialise if passed NULL + { + *ppTcb = tcbs; + return; + } + ++*ppTcb; //Increment + if (*ppTcb >= tcbs + TCB_COUNT) *ppTcb = tcbs; } uint32_t TcbElapsed = 0;