-
Notifications
You must be signed in to change notification settings - Fork 50
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
New PR for #19(Watchdog terminates the driver when debugging longer than 10s) #33
base: main
Are you sure you want to change the base?
Conversation
I thought this is what the Also, I'm not positive on the windows implementation for the bridge, but the linux one was written to be non-blocking, so wrapping it in a thread is fine, but doesn't do much. On the windows side, isn't there an option to set a timeout instead of blocking to wait for messages? |
As far as I know there is no flag, you could use SetCommTimeouts or change the pipes to Overlapped(Event based), but you would have to do that in SlimeServer as well. When I wrote it there was no linux implementation implemented. But it's been a few months :) https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setcommtimeouts |
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.
really, these are nitpicks. I have some other nitpicks that were not introduced as part of this PR, so I'm not opposed to merging as-is and cleaning it up later as I build on top of this to work on #34.
BRIDGE_ERROR = 2 | ||
}; | ||
|
||
explicit Bridge(VRDriver *i_pDriver); |
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.
why a pointer over a reference?
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.
Because I pass the class pointer from VRDriver -> src/VRDriver.cpp line 9
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.
You can still use a reference if you deref the pointer before passing it, like the old code was doing when it was passing a reference to the bridge every time it did something.
@@ -52,6 +54,7 @@ namespace SlimeVRDriver { | |||
vr::HmdVector3_t GetPosition(vr::HmdMatrix34_t &matrix); | |||
|
|||
bool sentHmdAddMessage = false; | |||
Bridge *m_pBridge; |
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.
Currently, we do not use (systems) hungarian notation in the driver. To be fair though, this is somewhat of a nitpick.
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.
Bridge *m_pBridge; | |
Bridge *bridge; |
should've included the suggestion in the original comment.
I don't want to make suggestions for every occurrence, because basically every single variable/parameter that you added does not follow the style of the rest of the driver, and I don't want to spam the PR.
this->stop(); | ||
} | ||
|
||
void SlimeVRDriver::Bridge::run() { |
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.
This appears to consist entirely of platform independent code, but is duplicated between windows pipes and unix sockets.
messages::ProtobufMessage oMsg; | ||
|
||
while (!this->m_bStop) { | ||
std::this_thread::sleep_for(std::chrono::milliseconds(3)); |
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.
Ideally, we'd wait for the OS to notify us that there's a message incoming, or we have a message in the queue that needs to be sent instead of sleeping for <arbitrary amount of time>.
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.
The sleep is a common practice to allow the cpu to switch the context to avoid high utilization.
In my eyes it would be the best to remove the pipes completely and send the data over TCP e.g. with Asio. Then you have only one implementation that works for windows and linux.
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.
I'm talking about using select or WaitForMultipleObjects instead of sleeping, meaning the OS can wake us up as soon as either there's an incoming message, or another thread sends a notification that there's an outgoing message, and we don't need to periodically wake-up to poll the outgoing queue.
This would still be applicable to a TCP based implementation, unless you had the other thread just send the message directly. (But that optimization would also apply to this implementation, so eh)
This doesn't need to be done right now, so I'll resolve the conversation after adding a TODO.
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.
std::this_thread::sleep_for(std::chrono::milliseconds(3)); | |
// TODO: use select, or a timeout, or just send the messages from another thread. | |
std::this_thread::sleep_for(std::chrono::milliseconds(3)); |
messages::ProtobufMessage oMsg; | ||
|
||
while (!this->m_bStop) { | ||
std::this_thread::sleep_for(std::chrono::milliseconds(3)); |
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.
std::this_thread::sleep_for(std::chrono::milliseconds(3)); | |
// TODO: use WaitForMultipleObjects, or a timeout, or just send the messages from another thread. | |
std::this_thread::sleep_for(std::chrono::milliseconds(3)); |
Fix for SteamVR quits when debugging SlimeVR server for more than 10 seconds
@Eirenliel New PR for #19