Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
tcp/tcb.c
- Committer:
- andrewboyson
- Date:
- 2018-01-18
- Revision:
- 65:37acccf2752f
- Parent:
- 61:aad055f1b0d1
- Child:
- 66:18a10c0b6d93
File content as of revision 65:37acccf2752f:
#include <stdint.h>
#include "log.h"
#include "tcp.h"
#include "tcb.h"
#include "tick.h"
#define TCB_COUNT 10
#define TIMEOUT_SYN_RECEIVED 2
#define TIMEOUT_ESTABLISHED 20
#define TIMEOUT_CLOSING 2
struct tcb tcbs[TCB_COUNT];
uint32_t TcbGetIsn()
{
static uint32_t isn = 0;
isn += 100000; //Gives each tcb 100,000 packets and won't repeat before 42,940 tcbs.
return isn;
}
struct tcb* TcbGetExisting(uint16_t port)
{
for (int i = 0; i < TCB_COUNT; i++)
{
struct tcb* pTcb = tcbs + i;
if (pTcb->state != TCB_EMPTY && pTcb->port == port) return pTcb;
}
return NULL;
}
struct tcb* TcbGetEmpty()
{
for (int i = 0; i < TCB_COUNT; i++)
{
struct tcb* pTcb = tcbs + i;
if (pTcb->state == TCB_EMPTY) return pTcb;
}
return NULL;
}
uint32_t TcbElapsed = 0;
static void reap()
{
static struct tcb* pTcb = tcbs;
if (pTcb->state == TCB_EMPTY) return;
uint32_t limit;
switch (pTcb->state)
{
case TCB_SYN_RECEIVED: limit = TIMEOUT_SYN_RECEIVED; break;
case TCB_ESTABLISHED: limit = TIMEOUT_ESTABLISHED; break;
case TCB_FIN_WAIT: limit = TIMEOUT_CLOSING; break;
case TCB_ACK_WAIT: limit = TIMEOUT_CLOSING; break;
}
if (TcbElapsed - pTcb->elapsed > limit)
{
if (TcpTrace) LogTimeF("Reaping TCB %d port %d\r\n", pTcb - tcbs, pTcb->port);
pTcb->state = TCB_EMPTY;
}
pTcb++;
if (pTcb >= tcbs + TCB_COUNT) pTcb = tcbs;
}
void TcbMain()
{
if (TickTicked) TcbElapsed++;
reap();
}
void TcbInit()
{
for (int i = 0; i < TCB_COUNT; i++) tcbs[i].state = TCB_EMPTY;
}