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

New PR for #19(Watchdog terminates the driver when debugging longer than 10s) #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DarkNebula0
Copy link

Fix for SteamVR quits when debugging SlimeVR server for more than 10 seconds

  • Rebased with new changes
  • Wrapped linux socket client

@Eirenliel New PR for #19

@funnbot
Copy link
Contributor

funnbot commented Jan 26, 2023

I thought this is what the --keepalive flag when launching vrserver is for.

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?
Using a thread is better, I'm just curious.

@DarkNebula0
Copy link
Author

I thought this is what the --keepalive flag when launching vrserver is for.

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? Using a thread is better, I'm just curious.

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

Copy link
Member

@kitlith kitlith left a 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);
Copy link
Member

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?

Copy link
Author

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

Copy link
Member

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;
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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() {
Copy link
Member

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));
Copy link
Member

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>.

Copy link
Author

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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));

@ButterscotchV ButterscotchV added Type: Bug Something isn't working Status: Help Wanted Needs some help to make progress Priority: Normal The default priority labels May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Normal The default priority Status: Help Wanted Needs some help to make progress Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants