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@145:206bf0d073c7, 2019-05-14 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue May 14 15:09:39 2019 +0000
- Revision:
- 145:206bf0d073c7
- Parent:
- 79:f50e02fb5c94
- Child:
- 146:0fc66d610fd6
Added a shim module between the web server and TCP to switch between http (direct) and https (tls).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 61:aad055f1b0d1 | 1 | #include <stdbool.h> |
andrewboyson | 61:aad055f1b0d1 | 2 | #include <stdio.h> |
andrewboyson | 61:aad055f1b0d1 | 3 | |
andrewboyson | 54:84ef2b29cf7e | 4 | #include "http.h" |
andrewboyson | 54:84ef2b29cf7e | 5 | |
andrewboyson | 79:f50e02fb5c94 | 6 | static uint32_t currentPositionInMessage; |
andrewboyson | 79:f50e02fb5c94 | 7 | static uint32_t bufferPositionInMessage; |
andrewboyson | 54:84ef2b29cf7e | 8 | static int bufferLength; |
andrewboyson | 54:84ef2b29cf7e | 9 | static char* pBuffer; |
andrewboyson | 54:84ef2b29cf7e | 10 | static char* p; |
andrewboyson | 54:84ef2b29cf7e | 11 | |
andrewboyson | 79:f50e02fb5c94 | 12 | void TcpBufStart(uint32_t position, int mss, char *pData) |
andrewboyson | 54:84ef2b29cf7e | 13 | { |
andrewboyson | 54:84ef2b29cf7e | 14 | currentPositionInMessage = 0; |
andrewboyson | 54:84ef2b29cf7e | 15 | bufferPositionInMessage = position; |
andrewboyson | 54:84ef2b29cf7e | 16 | bufferLength = mss; |
andrewboyson | 54:84ef2b29cf7e | 17 | pBuffer = pData; |
andrewboyson | 54:84ef2b29cf7e | 18 | p = pData; |
andrewboyson | 54:84ef2b29cf7e | 19 | } |
andrewboyson | 54:84ef2b29cf7e | 20 | int TcpBufLength() |
andrewboyson | 54:84ef2b29cf7e | 21 | { |
andrewboyson | 54:84ef2b29cf7e | 22 | return p - pBuffer; |
andrewboyson | 54:84ef2b29cf7e | 23 | } |
andrewboyson | 145:206bf0d073c7 | 24 | bool TcpBufFilled() |
andrewboyson | 145:206bf0d073c7 | 25 | { |
andrewboyson | 145:206bf0d073c7 | 26 | return p - pBuffer >= bufferLength; |
andrewboyson | 145:206bf0d073c7 | 27 | } |
andrewboyson | 54:84ef2b29cf7e | 28 | |
andrewboyson | 54:84ef2b29cf7e | 29 | void TcpBufAddChar(char c) |
andrewboyson | 54:84ef2b29cf7e | 30 | { |
andrewboyson | 145:206bf0d073c7 | 31 | //Add character if the current position is within the buffer |
andrewboyson | 145:206bf0d073c7 | 32 | if (currentPositionInMessage >= bufferPositionInMessage && |
andrewboyson | 145:206bf0d073c7 | 33 | currentPositionInMessage < bufferPositionInMessage + bufferLength) *p++ = c; |
andrewboyson | 145:206bf0d073c7 | 34 | |
andrewboyson | 54:84ef2b29cf7e | 35 | currentPositionInMessage++; |
andrewboyson | 54:84ef2b29cf7e | 36 | } |