last packet optimization (#3363)
* last packet optimization * comment * test * missed one * set tcp mss
This commit is contained in:
parent
22a811d311
commit
e4c34e016a
|
@ -45,7 +45,7 @@ void TsChannelBase::writeCrcPacketSmall(uint8_t responseCode, const uint8_t* buf
|
|||
*reinterpret_cast<uint32_t*>(&scratchBuffer[size + 3]) = SWAP_UINT32(crc);
|
||||
|
||||
// Write to the underlying stream
|
||||
write(reinterpret_cast<uint8_t*>(scratchBuffer), size + 7);
|
||||
write(reinterpret_cast<uint8_t*>(scratchBuffer), size + 7, true);
|
||||
}
|
||||
|
||||
void TsChannelBase::writeCrcPacketLarge(uint8_t responseCode, const uint8_t* buf, size_t size) {
|
||||
|
@ -62,15 +62,15 @@ void TsChannelBase::writeCrcPacketLarge(uint8_t responseCode, const uint8_t* buf
|
|||
*(uint32_t*)crcBuffer = SWAP_UINT32(crc);
|
||||
|
||||
// Write header
|
||||
write(headerBuffer, sizeof(headerBuffer));
|
||||
write(headerBuffer, sizeof(headerBuffer), false);
|
||||
|
||||
// If data, write that
|
||||
if (size) {
|
||||
write(buf, size);
|
||||
write(buf, size, false);
|
||||
}
|
||||
|
||||
// Lastly the CRC footer
|
||||
write(crcBuffer, sizeof(crcBuffer));
|
||||
write(crcBuffer, sizeof(crcBuffer), true);
|
||||
}
|
||||
|
||||
TsChannelBase::TsChannelBase(const char *name) {
|
||||
|
@ -101,7 +101,7 @@ void TsChannelBase::sendResponse(ts_response_format_e mode, const uint8_t * buff
|
|||
writeCrcPacket(TS_RESPONSE_OK, buffer, size);
|
||||
} else {
|
||||
if (size > 0) {
|
||||
write(buffer, size);
|
||||
write(buffer, size, true);
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class TsChannelBase {
|
|||
public:
|
||||
TsChannelBase(const char *name);
|
||||
// Virtual functions - implement these for your underlying transport
|
||||
virtual void write(const uint8_t* buffer, size_t size) = 0;
|
||||
virtual void write(const uint8_t* buffer, size_t size, bool isEndOfPacket = false) = 0;
|
||||
virtual size_t readTimeout(uint8_t* buffer, size_t size, int timeout) = 0;
|
||||
|
||||
// These functions are optional to implement, not all channels need them
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
void start(uint32_t baud) override;
|
||||
void stop() override;
|
||||
|
||||
void write(const uint8_t* buffer, size_t size) override;
|
||||
void write(const uint8_t* buffer, size_t size, bool isEndOfPacket) override;
|
||||
size_t readTimeout(uint8_t* buffer, size_t size, int timeout) override;
|
||||
|
||||
private:
|
||||
|
@ -101,7 +101,7 @@ public:
|
|||
void start(uint32_t baud) override;
|
||||
void stop() override;
|
||||
|
||||
void write(const uint8_t* buffer, size_t size) override;
|
||||
void write(const uint8_t* buffer, size_t size, bool isEndOfPacket) override;
|
||||
size_t readTimeout(uint8_t* buffer, size_t size, int timeout) override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -23,7 +23,7 @@ void SerialTsChannel::stop() {
|
|||
sdStop(m_driver);
|
||||
}
|
||||
|
||||
void SerialTsChannel::write(const uint8_t* buffer, size_t size) {
|
||||
void SerialTsChannel::write(const uint8_t* buffer, size_t size, bool) {
|
||||
chnWriteTimeout(m_driver, buffer, size, BINARY_IO_TIMEOUT);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ void UartTsChannel::stop() {
|
|||
uartStop(m_driver);
|
||||
}
|
||||
|
||||
void UartTsChannel::write(const uint8_t* buffer, size_t size) {
|
||||
void UartTsChannel::write(const uint8_t* buffer, size_t size, bool) {
|
||||
uartSendTimeout(m_driver, &size, buffer, BINARY_IO_TIMEOUT);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,11 @@ public:
|
|||
return connectionSocket != -1;
|
||||
}
|
||||
|
||||
void write(const uint8_t* buffer, size_t size) override {
|
||||
lwip_send(connectionSocket, buffer, size, /*flags =*/ 0);
|
||||
void write(const uint8_t* buffer, size_t size, bool isEndOfPacket) override {
|
||||
// If not the end of a packet, set the MSG_MORE flag to indicate to the transport
|
||||
// that we have more to add to the buffer before queuing a flush.
|
||||
auto flags = isEndOfPacket ? 0 : MSG_MORE;
|
||||
lwip_send(connectionSocket, buffer, size, flags);
|
||||
}
|
||||
|
||||
size_t readTimeout(uint8_t* buffer, size_t size, int /*timeout*/) override {
|
||||
|
|
|
@ -76,4 +76,9 @@
|
|||
#define LWIP_ETHADDR_4 0x34
|
||||
#define LWIP_ETHADDR_5 0x56
|
||||
|
||||
#include "rusefi_generated.h"
|
||||
|
||||
// Ensure that one TCP segment can always fit an entire response to TS - we never need to split a TS packet across multiple frames.
|
||||
#define TCP_MSS (BLOCKING_FACTOR + 10)
|
||||
|
||||
#endif /* LWIP_HDR_LWIPOPTS_H__ */
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
return is_usb_serial_ready();
|
||||
}
|
||||
|
||||
void write(const uint8_t* buffer, size_t size) override {
|
||||
void write(const uint8_t* buffer, size_t size, bool) override {
|
||||
chnWriteTimeout(m_channel, buffer, size, BINARY_IO_TIMEOUT);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class MockTsChannel : public TsChannelBase {
|
|||
public:
|
||||
MockTsChannel() : TsChannelBase("Test") { }
|
||||
|
||||
void write(const uint8_t* buffer, size_t size) override {
|
||||
void write(const uint8_t* buffer, size_t size, bool /*isLastWriteInTransaction*/) override {
|
||||
memcpy(&st5TestBuffer[writeIdx], buffer, size);
|
||||
writeIdx += size;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue