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/http/http.c
- Revision:
- 144:6bd5c54efc7d
- Parent:
- 142:a8c0890a58d1
- Child:
- 145:206bf0d073c7
--- a/tcp/http/http.c Thu May 09 07:47:12 2019 +0000 +++ b/tcp/http/http.c Sun May 12 17:17:49 2019 +0000 @@ -7,14 +7,15 @@ #include "log.h" #include "led.h" #include "restart.h" +#include "mstimer.h" bool HttpTrace = false; //Plumb into these from your html server -void (*HttpRequestFunction)(int size, char* pRequestStream, uint32_t positionInRequestStream, int* pToDo, bool* pPostComplete, uint32_t* pDelayUntil); -void (*HttpReplyFunction )(int todo); +void (*HttpRequestFunction)(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState); +int (*HttpReplyFunction )(char* pState); -void HttpHandleRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, int* pToDo, bool* pPostComplete, uint32_t* pDelayUntil) +void HttpHandleRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, char* pState) { int lastRestartPoint = RestartPoint; RestartPoint = FAULT_POINT_HttpHandleRequest; @@ -24,18 +25,22 @@ LogF("HTTP <<< %d (%u)\r\n", size, positionInRequestStream); } - HttpRequestFunction(size, pRequestStream, positionInRequestStream, pToDo, pPostComplete, pDelayUntil); + HttpRequestFunction(size, pRequestStream, positionInRequestStream, pState); RestartPoint = lastRestartPoint; } -void HttpSendReply(int* pSize, char* pReplyStream, uint32_t positionInReplyStream, uint16_t mss, int todo) +int HttpSendReply(int* pSize, char* pReplyStream, uint32_t positionInReplyStream, uint16_t mss, char* pState) { TcpBufStart(positionInReplyStream, mss, pReplyStream); - HttpReplyFunction(todo); + int status = HttpReplyFunction(pState); //0: not started; +1: started; -1: wait + if (status == 0) return TCP_APP_NOT_STARTED; + if (status == -1) return TCP_APP_STARTED; + *pSize = TcpBufLength(); if (HttpTrace) { LogF("HTTP >>> %d (%d)\r\n", *pSize, positionInReplyStream); } + return *pSize < mss ? TCP_APP_FINISHED : TCP_APP_STARTED; }