Skip to content

Commit

Permalink
Merge branch 'master' into stack/cont-overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
d-a-v authored Mar 25, 2024
2 parents c4e7642 + 41ecd65 commit 9b64017
Show file tree
Hide file tree
Showing 21 changed files with 481 additions and 192 deletions.
2 changes: 1 addition & 1 deletion cores/esp8266/LwipIntf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern "C"
// can return nullptr when STA is down
// - Because WiFi is started in off mode at boot time,
// wifi_station_set/get_hostname() is now no more used
// because setting hostname firt does not work anymore
// because setting hostname first does not work anymore
// - wifi_station_hostname is overwritten by SDK when wifi is
// woken up in WiFi::mode()
//
Expand Down
4 changes: 4 additions & 0 deletions cores/esp8266/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,25 @@ class Stream: public Print {
// returns number of transferred bytes
size_t sendAvailable (Stream* to) { return sendGeneric(to, -1, -1, oneShotMs::alwaysExpired); }
size_t sendAvailable (Stream& to) { return sendAvailable(&to); }
size_t sendAvailable (Stream&& to) { return sendAvailable(&to); }

// transfers data until timeout
// returns number of transferred bytes
size_t sendAll (Stream* to, const oneShotMs::timeType timeoutMs = oneShotMs::neverExpires) { return sendGeneric(to, -1, -1, timeoutMs); }
size_t sendAll (Stream& to, const oneShotMs::timeType timeoutMs = oneShotMs::neverExpires) { return sendAll(&to, timeoutMs); }
size_t sendAll (Stream&& to, const oneShotMs::timeType timeoutMs = oneShotMs::neverExpires) { return sendAll(&to, timeoutMs); }

// transfers data until a char is encountered (the char is swallowed but not transferred) with timeout
// returns number of transferred bytes
size_t sendUntil (Stream* to, const int readUntilChar, const oneShotMs::timeType timeoutMs = oneShotMs::neverExpires) { return sendGeneric(to, -1, readUntilChar, timeoutMs); }
size_t sendUntil (Stream& to, const int readUntilChar, const oneShotMs::timeType timeoutMs = oneShotMs::neverExpires) { return sendUntil(&to, readUntilChar, timeoutMs); }
size_t sendUntil (Stream&& to, const int readUntilChar, const oneShotMs::timeType timeoutMs = oneShotMs::neverExpires) { return sendUntil(&to, readUntilChar, timeoutMs); }

// transfers data until requested size or timeout
// returns number of transferred bytes
size_t sendSize (Stream* to, const ssize_t maxLen, const oneShotMs::timeType timeoutMs = oneShotMs::neverExpires) { return sendGeneric(to, maxLen, -1, timeoutMs); }
size_t sendSize (Stream& to, const ssize_t maxLen, const oneShotMs::timeType timeoutMs = oneShotMs::neverExpires) { return sendSize(&to, maxLen, timeoutMs); }
size_t sendSize (Stream&& to, const ssize_t maxLen, const oneShotMs::timeType timeoutMs = oneShotMs::neverExpires) { return sendSize(&to, maxLen, timeoutMs); }

// remaining size (-1 by default = unknown)
virtual ssize_t streamRemaining () { return -1; }
Expand Down
16 changes: 8 additions & 8 deletions cores/esp8266/StreamString.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "WString.h"

///////////////////////////////////////////////////////////////
// S2Stream points to a String and makes it a Stream
// S2Stream ("String to Stream") points to a String and makes it a Stream
// (it is also the helper for StreamString)

class S2Stream: public Stream
Expand Down Expand Up @@ -184,26 +184,26 @@ class S2Stream: public Stream
return peekPointer < 0 ? string->length() : string->length() - peekPointer;
}

// calling setConsume() will consume bytes as the stream is read
// (enabled by default)
// calling setConsume() will make the string consumed as the stream is read.
// (default behaviour)
void setConsume()
{
peekPointer = -1;
}

// Reading this stream will mark the string as read without consuming
// (not enabled by default)
// Calling resetPointer() resets the read state and allows rereading.
void resetPointer(int pointer = 0)
// Calling resetPointer() resets the read cursor and allows rereading.
// (this is the opposite of default mode set by setConsume())
void resetPointer(size_t pointer = 0)
{
peekPointer = pointer;
peekPointer = std::min(pointer, (size_t)string->length());
}

protected:
String* string;
int peekPointer; // -1:String is consumed / >=0:resettable pointer
};

///////////////////////////////////////////////////////////////
// StreamString is a S2Stream holding the String

class StreamString: public String, public S2Stream
Expand Down
Loading

0 comments on commit 9b64017

Please sign in to comment.