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

tcp/tcpbuf.c

Committer:
andrewboyson
Date:
2019-05-14
Revision:
145:206bf0d073c7
Parent:
79:f50e02fb5c94
Child:
146:0fc66d610fd6

File content as of revision 145:206bf0d073c7:

#include <stdbool.h>
#include <stdio.h>

#include "http.h"

static uint32_t currentPositionInMessage;
static uint32_t bufferPositionInMessage;
static int bufferLength;
static char* pBuffer;
static char* p;

void TcpBufStart(uint32_t position, int mss, char *pData)
{
    currentPositionInMessage = 0;
    bufferPositionInMessage = position;
    bufferLength = mss;
    pBuffer = pData;
    p       = pData;
}
int TcpBufLength()
{
    return p - pBuffer;
}
bool TcpBufFilled()
{
    return p - pBuffer >= bufferLength;
}

void TcpBufAddChar(char c)
{
    //Add character if the current position is within the buffer
    if (currentPositionInMessage >= bufferPositionInMessage &&
        currentPositionInMessage <  bufferPositionInMessage + bufferLength) *p++ = c;
    
    currentPositionInMessage++;
}