1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Stream::send() (#6979)

This commit is contained in:
david gauchard
2021-03-15 01:36:20 +01:00
committed by GitHub
parent 4cc1472821
commit c720c0d9e8
48 changed files with 2136 additions and 650 deletions

View File

@ -64,7 +64,7 @@ $(TEST_LIST):
$(SILENT)mkdir -p $(LOCAL_BUILD_DIR)
ifeq ("$(MOCK)", "1")
@echo Compiling $(notdir $@)
(cd ../host; make ULIBDIRS=../device/libraries/BSTest ../device/$(@:%.ino=%))
(cd ../host; make D=$(V) ULIBDIRS=../device/libraries/BSTest ../device/$(@:%.ino=%))
$(SILENT)source $(BS_DIR)/virtualenv/bin/activate && \
$(PYTHON) $(BS_DIR)/runner.py \
$(RUNNER_DEBUG_FLAG) \

View File

@ -0,0 +1,25 @@
#include <Arduino.h>
#include <BSTest.h>
#define check(what, res1, res2) CHECK(strcmp(res1, res2) == 0)
#include "../../../libraries/esp8266/examples/StreamString/StreamString.ino"
BS_ENV_DECLARE();
bool pretest ()
{
return true;
}
void setup ()
{
Serial.begin(115200);
BS_RUN(Serial);
}
TEST_CASE("StreamString tests", "[StreamString]")
{
testStream();
}

View File

@ -11,6 +11,7 @@ def setup_echo_server(e):
global stop_client_thread
global client_thread
def echo_client_thread():
time.sleep(1) # let some time for mDNS to start
server_address = socket.gethostbyname('esp8266-wfs-test.local')
count = 0
while count < 5 and not stop_client_thread:

View File

@ -76,7 +76,7 @@ $(shell mkdir -p $(BINDIR))
CORE_CPP_FILES := \
$(addprefix $(abspath $(CORE_PATH))/,\
debug.cpp \
StreamString.cpp \
StreamSend.cpp \
Stream.cpp \
WString.cpp \
Print.cpp \

View File

@ -80,4 +80,3 @@ cont_t* g_pcont = NULL;
extern "C" void cont_yield(cont_t*)
{
}

View File

@ -89,7 +89,8 @@ ssize_t mockFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize)
if (ret == 0)
{
// connection closed
return -1;
// nothing is read
return 0;
}
if (ret == -1)
@ -97,16 +98,20 @@ ssize_t mockFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize)
if (errno != EAGAIN)
{
fprintf(stderr, MOCK "ClientContext::(read/peek fd=%i): filling buffer for %zd bytes: %s\n", sock, maxread, strerror(errno));
// error
return -1;
}
ret = 0;
}
ccinbufsize += ret;
return ret;
}
ssize_t mockPeekBytes (int sock, char* dst, size_t usersize, int timeout_ms, char* ccinbuf, size_t& ccinbufsize)
{
// usersize==0: peekAvailable()
if (usersize > CCBUFSIZE)
mockverbose("CCBUFSIZE(%d) should be increased by %zd bytes (-> %zd)\n", CCBUFSIZE, usersize - CCBUFSIZE, usersize);
@ -114,7 +119,7 @@ ssize_t mockPeekBytes (int sock, char* dst, size_t usersize, int timeout_ms, cha
size_t retsize = 0;
do
{
if (usersize <= ccinbufsize)
if (usersize && usersize <= ccinbufsize)
{
// data already buffered
retsize = usersize;
@ -123,7 +128,14 @@ ssize_t mockPeekBytes (int sock, char* dst, size_t usersize, int timeout_ms, cha
// check incoming data data
if (mockFillInBuf(sock, ccinbuf, ccinbufsize) < 0)
{
return -1;
}
if (usersize == 0 && ccinbufsize)
// peekAvailable
return ccinbufsize;
if (usersize <= ccinbufsize)
{
// data just received
@ -179,7 +191,7 @@ ssize_t mockWrite (int sock, const uint8_t* data, size_t size, int timeout_ms)
#endif
if (ret == -1)
{
fprintf(stderr, MOCK "ClientContext::read: write(%d): %s\n", sock, strerror(errno));
fprintf(stderr, MOCK "ClientContext::write/send(%d): %s\n", sock, strerror(errno));
return -1;
}
sent += ret;
@ -187,6 +199,8 @@ ssize_t mockWrite (int sock, const uint8_t* data, size_t size, int timeout_ms)
fprintf(stderr, MOCK "ClientContext::write: sent %d bytes (%zd / %zd)\n", ret, sent, size);
}
}
fprintf(stderr, MOCK "ClientContext::write: total sent %zd bytes\n", sent);
#ifdef DEBUG_ESP_WIFI
mockverbose(MOCK "ClientContext::write: total sent %zd bytes\n", sent);
#endif
return sent;
}

View File

@ -491,3 +491,9 @@ uart_detect_baudrate(int uart_nr)
}
};
size_t uart_peek_available (uart_t* uart) { return 0; }
const char* uart_peek_buffer (uart_t* uart) { return nullptr; }
void uart_peek_consume (uart_t* uart, size_t consume) { (void)uart; (void)consume; }

View File

@ -27,7 +27,7 @@ class WiFiClient;
extern "C" void esp_yield();
extern "C" void esp_schedule();
#include <include/DataSource.h>
#include <assert.h>
bool getDefaultPrivateGlobalSyncValue ();
@ -300,6 +300,33 @@ public:
_sync = sync;
}
// return a pointer to available data buffer (size = peekAvailable())
// semantic forbids any kind of read() before calling peekConsume()
const char* peekBuffer ()
{
return _inbuf;
}
// return number of byte accessible by peekBuffer()
size_t peekAvailable ()
{
ssize_t ret = mockPeekBytes(_sock, nullptr, 0, 0, _inbuf, _inbufsize);
if (ret < 0)
{
abort();
return 0;
}
return _inbufsize;
}
// consume bytes after use (see peekBuffer)
void peekConsume (size_t consume)
{
assert(consume <= _inbufsize);
memmove(_inbuf, _inbuf + consume, _inbufsize - consume);
_inbufsize -= consume;
}
private:
discard_cb_t _discard_cb = nullptr;

View File

@ -15,8 +15,10 @@ libraries/ESP8266mDNS
libraries/Wire
libraries/lwIP*
cores/esp8266/Lwip*
cores/esp8266/core_esp8266_si2c.cpp
cores/esp8266/debug*
cores/esp8266/core_esp8266_si2c.cpp
cores/esp8266/StreamString.*
cores/esp8266/StreamSend.*
libraries/Netdump
"