arduino / arduino/ArduinoCore-avr

Loosing last byte with readBytesUntil

Open
#290 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I have following code:
```
client_len = serverClients[i].readBytesUntil(_EOF, client_buf, MAX_FRAME_LENGTH);
client_buf[client_len++] = serverClients[i].read();
if (client_buf[client_len-1] != _EOF){
//something strange happened
serverClients[i].write("uhm");
continue;
}
```
How should I distinguish if _EOF character or MAX_FRAME_LENGTH or timeout has been reached?
The implementation reads the terminating character but then it is lost (not written to output buffer):
https://github.com/arduino/ArduinoCore-avr/blob/317513b9c989de24d438de7ac55d701b738881e2/cores/arduino/Stream.cpp#L224

See also: https://github.com/esp8266/Arduino/issues/6546

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at cores/arduino/Stream.cpp around line 224 and inspect readBytesUntil's return value and terminator handling. Compare the behavior with the usage shown in the issue and the related ESP8266 issue. Done means the API or its documentation clearly distinguishes EOF, buffer length, and timeout, without unexpectedly losing the terminating byte.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.