mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-11 15:22:13 +03:00
deprecate and update Stream::send*(Print -> Stream)
(#8874)
* deprecate and update Stream::send(Print -> Stream) in order to benefit from and use output's timeout value
This commit is contained in:
@ -22,9 +22,17 @@
|
||||
#include <Arduino.h>
|
||||
#include <StreamDev.h>
|
||||
|
||||
size_t Stream::sendGeneric(Print* to, const ssize_t len, const int readUntilChar,
|
||||
size_t Stream::sendGeneric(Stream* to, const ssize_t len, const int readUntilChar,
|
||||
const esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs)
|
||||
{
|
||||
// "neverExpires (default, impossible)" is translated to default timeout
|
||||
esp8266::polledTimeout::oneShotFastMs::timeType inputTimeoutMs
|
||||
= timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout()
|
||||
: timeoutMs;
|
||||
|
||||
esp8266::polledTimeout::oneShotFastMs::timeType mainTimeoutMs = std::max(
|
||||
inputTimeoutMs, (esp8266::polledTimeout::oneShotFastMs::timeType)to->getTimeout());
|
||||
|
||||
setReport(Report::Success);
|
||||
|
||||
if (len == 0)
|
||||
@ -43,25 +51,60 @@ size_t Stream::sendGeneric(Print* to, const ssize_t len, const int readUntilChar
|
||||
|
||||
if (hasPeekBufferAPI())
|
||||
{
|
||||
return SendGenericPeekBuffer(to, len, readUntilChar, timeoutMs);
|
||||
return SendGenericPeekBuffer(to, len, readUntilChar, mainTimeoutMs);
|
||||
}
|
||||
|
||||
if (readUntilChar >= 0)
|
||||
{
|
||||
return SendGenericRegularUntil(to, len, readUntilChar, timeoutMs);
|
||||
return SendGenericRegularUntil(to, len, readUntilChar, mainTimeoutMs);
|
||||
}
|
||||
|
||||
return SendGenericRegular(to, len, timeoutMs);
|
||||
return SendGenericRegular(to, len, mainTimeoutMs);
|
||||
}
|
||||
|
||||
size_t Stream::sendGeneric(Print* to, const ssize_t len, const int readUntilChar,
|
||||
const esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs)
|
||||
{
|
||||
// "neverExpires (default, impossible)" is translated to default timeout
|
||||
esp8266::polledTimeout::oneShotFastMs::timeType inputTimeoutMs
|
||||
= timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout()
|
||||
: timeoutMs;
|
||||
|
||||
setReport(Report::Success);
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
return 0; // conveniently avoids timeout for no requested data
|
||||
}
|
||||
|
||||
// There are two timeouts:
|
||||
// - read (network, serial, ...)
|
||||
// - write (network, serial, ...)
|
||||
// However
|
||||
// - getTimeout() is for reading only
|
||||
// - there is no getOutputTimeout() api
|
||||
// So we use getTimeout() for both,
|
||||
// (also when inputCanTimeout() is false)
|
||||
|
||||
if (hasPeekBufferAPI())
|
||||
{
|
||||
return SendGenericPeekBuffer(to, len, readUntilChar, inputTimeoutMs);
|
||||
}
|
||||
|
||||
if (readUntilChar >= 0)
|
||||
{
|
||||
return SendGenericRegularUntil(to, len, readUntilChar, inputTimeoutMs);
|
||||
}
|
||||
|
||||
return SendGenericRegular(to, len, inputTimeoutMs);
|
||||
}
|
||||
|
||||
size_t
|
||||
Stream::SendGenericPeekBuffer(Print* to, const ssize_t len, const int readUntilChar,
|
||||
const esp8266::polledTimeout::oneShotFastMs::timeType timeoutMs)
|
||||
{
|
||||
// "neverExpires (default, impossible)" is translated to default timeout
|
||||
esp8266::polledTimeout::oneShotFastMs timedOut(
|
||||
timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout()
|
||||
: timeoutMs);
|
||||
esp8266::polledTimeout::oneShotFastMs timedOut(timeoutMs);
|
||||
|
||||
// len==-1 => maxLen=0 <=> until starvation
|
||||
const size_t maxLen = std::max((ssize_t)0, len);
|
||||
size_t written = 0;
|
||||
@ -152,10 +195,8 @@ Stream::SendGenericRegularUntil(Print* to, const ssize_t len, const int readUnti
|
||||
// regular Stream API
|
||||
// no other choice than reading byte by byte
|
||||
|
||||
// "neverExpires (default, impossible)" is translated to default timeout
|
||||
esp8266::polledTimeout::oneShotFastMs timedOut(
|
||||
timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout()
|
||||
: timeoutMs);
|
||||
esp8266::polledTimeout::oneShotFastMs timedOut(timeoutMs);
|
||||
|
||||
// len==-1 => maxLen=0 <=> until starvation
|
||||
const size_t maxLen = std::max((ssize_t)0, len);
|
||||
size_t written = 0;
|
||||
@ -231,10 +272,8 @@ size_t Stream::SendGenericRegular(Print* to, const ssize_t len,
|
||||
// regular Stream API
|
||||
// use an intermediary buffer
|
||||
|
||||
// "neverExpires (default, impossible)" is translated to default timeout
|
||||
esp8266::polledTimeout::oneShotFastMs timedOut(
|
||||
timeoutMs >= esp8266::polledTimeout::oneShotFastMs::neverExpires ? getTimeout()
|
||||
: timeoutMs);
|
||||
esp8266::polledTimeout::oneShotFastMs timedOut(timeoutMs);
|
||||
|
||||
// len==-1 => maxLen=0 <=> until starvation
|
||||
const size_t maxLen = std::max((ssize_t)0, len);
|
||||
size_t written = 0;
|
||||
|
Reference in New Issue
Block a user