Skip to content
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

Linux low latency fix (allow set without changing low latency mode) #2241

Merged
merged 5 commits into from
May 26, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions packages/bindings/src/serialport_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int linuxSetCustomBaudRate(const int fd, const unsigned int baudrate) {
t.c_cflag |= BOTHER;
t.c_ospeed = t.c_ispeed = baudrate;

if (ioctl(fd, TCSETS2, &t)) {
if (ioctl(fd, TCSETS2, &t) < 0) {
return -2;
}

Expand All @@ -43,22 +43,19 @@ int linuxSetLowLatencyMode(const int fd, const bool enable) {
if (ioctl(fd, TIOCGSERIAL, &ss)) {
return -1;
}

int oldFlags = ss.flags;

if (enable) {
ss.flags |= ASYNC_LOW_LATENCY;
} else {
ss.flags &= ~ASYNC_LOW_LATENCY;
}
if (ss.flags & ASYNC_LOW_LATENCY != enable) {

Copy link
Member

Choose a reason for hiding this comment

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

just a nitpick it's better to return early than it is to nest

if (enable) {
ss.flags |= ASYNC_LOW_LATENCY;
} else {
ss.flags &= ~ASYNC_LOW_LATENCY;
}

if (oldFlags != ss.flags)
{
if (ioctl(fd, TIOCSSERIAL, &ss)) {
if (ioctl(fd, TIOCSSERIAL, &ss) < 0) {
Copy link
Member

Choose a reason for hiding this comment

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

another nitpick ioctl will always return -1 on error never anything else

return -2;
}
}

return 0;
}

Expand Down