-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b8e1a48
only set lowLatency if defined
GazHank ca2c3d8
fix set and get methods for low_latency
GazHank 7310751
clarify error messages
GazHank 60a167b
Merge pull request #1 from GazHank/pr/GazHank/2241-1
GazHank 1e0d14f
Changes based on feedback
GazHank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
|
@@ -44,16 +44,30 @@ int linuxSetLowLatencyMode(const int fd, const bool enable) { | |
return -1; | ||
} | ||
|
||
if (enable) { | ||
ss.flags |= ASYNC_LOW_LATENCY; | ||
} else { | ||
ss.flags &= ~ASYNC_LOW_LATENCY; | ||
if (ss.flags & ASYNC_LOW_LATENCY != enable) { | ||
|
||
if (enable) { | ||
ss.flags |= ASYNC_LOW_LATENCY; | ||
} else { | ||
ss.flags &= ~ASYNC_LOW_LATENCY; | ||
} | ||
|
||
if (ioctl(fd, TIOCSSERIAL, &ss) < 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
if (ioctl(fd, TIOCSSERIAL, &ss)) { | ||
return -2; | ||
int linuxGetLowLatencyMode(const int fd, bool* const enabled) { | ||
struct serial_struct ss; | ||
|
||
if (ioctl(fd, TIOCGSERIAL, &ss)) { | ||
return -1; | ||
} | ||
|
||
*enabled = ss.flags & ASYNC_LOW_LATENCY; | ||
|
||
return 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,17 +332,6 @@ void EIO_Set(uv_work_t* req) { | |
bits |= TIOCM_DSR; | ||
} | ||
|
||
#if defined(__linux__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good move |
||
int err = linuxSetLowLatencyMode(data->fd, data->lowLatency); | ||
if (err == -1) { | ||
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, cannot get", strerror(errno)); | ||
return; | ||
} else if(err == -2) { | ||
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, cannot set", strerror(errno)); | ||
return; | ||
} | ||
#endif | ||
|
||
int result = 0; | ||
if (data->brk) { | ||
result = ioctl(data->fd, TIOCSBRK, NULL); | ||
|
@@ -359,6 +348,17 @@ void EIO_Set(uv_work_t* req) { | |
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, cannot set", strerror(errno)); | ||
return; | ||
} | ||
|
||
#if defined(__linux__) | ||
int err = linuxSetLowLatencyMode(data->fd, data->lowLatency); | ||
if (err == -1) { | ||
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, cannot get low latency", strerror(errno)); | ||
return; | ||
} else if(err == -2) { | ||
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, cannot set low latency", strerror(errno)); | ||
return; | ||
} | ||
#endif | ||
} | ||
|
||
void EIO_Get(uv_work_t* req) { | ||
|
@@ -370,19 +370,20 @@ void EIO_Get(uv_work_t* req) { | |
return; | ||
} | ||
|
||
data->lowLatency = false; | ||
data->cts = bits & TIOCM_CTS; | ||
data->dsr = bits & TIOCM_DSR; | ||
data->dcd = bits & TIOCM_CD; | ||
|
||
#if defined(__linux__) && defined(ASYNC_LOW_LATENCY) | ||
int latency_bits; | ||
if (-1 == ioctl(data->fd, TIOCGSERIAL, &latency_bits)) { | ||
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, cannot get", strerror(errno)); | ||
bool lowlatency = false; | ||
if (-1 == linuxGetLowLatencyMode(data->fd, &lowlatency)) { | ||
snprintf(data->errorString, sizeof(data->errorString), "Error: %s, cannot get low latency", strerror(errno)); | ||
return; | ||
} | ||
data->lowLatency = latency_bits & ASYNC_LOW_LATENCY; | ||
data->lowLatency = lowlatency; | ||
#else | ||
data->lowLatency = false; | ||
#endif | ||
|
||
data->cts = bits & TIOCM_CTS; | ||
data->dsr = bits & TIOCM_DSR; | ||
data->dcd = bits & TIOCM_CD; | ||
} | ||
|
||
void EIO_GetBaudRate(uv_work_t* req) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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