Skip to content

Move stdin processing to yield() #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2021
Merged

Move stdin processing to yield() #32

merged 1 commit into from
Jul 15, 2021

Conversation

lopsided98
Copy link
Contributor

Before this patch, stdin is only read between calls to loop(). This causes problems when a program waits for serial input while calling yield() in a loop. Moving the stdin handling code to yield() fixes this problem and more closely matches real hardware behavior.

Also, this patch checks the return value from read(), which fixes a compiler warning and allows null bytes to be read correctly.

@@ -22,6 +22,11 @@
// -----------------------------------------------------------------------

void yield() {
char c = '\0';
if (read(STDIN_FILENO, &c, 1) == 1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Just out of curiosity, how did you hit this bug? Sending a NUL character into the Serial port seems like a rare thing.. unless you were sending binary data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't actually run into that bug. I was fixing the unused result compiler warning and noticed that it would also fix the NUL issue.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The strange thing is that I have both -Wall and -Wextra enabled by default. According to the documentations I see online, those imply -Wunused-result which should warn me about this. But neither g++ nor clang++ on Linux (Ubuntu 20.04) will trigger a warning for me.

Anyway, I will merge this.

Before this patch, stdin is only read between calls to loop(). This
causes problems when a program waits for serial input while calling
yield() in a loop. Moving the stdin handling code to yield() fixes this
problem and more closely matches real hardware behavior.

Also, this patch checks the return value from read(), which fixes a
compiler warning and allows null bytes to be read correctly.
@bxparks bxparks merged commit 419c8c1 into bxparks:develop Jul 15, 2021
bxparks added a commit to hsaturn/EspMock that referenced this pull request Jul 15, 2021
@bxparks bxparks mentioned this pull request Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants