FreeSpacenav / libspnav

Library for communicating with spacenavd or 3dxsrv to get input from 6-dof devices.
http://spacenav.sourceforge.net
Other
75 stars 36 forks source link

spnav_close doesn't cause spnav_read to exit. #10

Closed tlbtlbtlb closed 4 years ago

tlbtlbtlb commented 4 years ago

In my application, I have a thread calling spnav_read in a loop. When quitting the application, I want to call spnav_close and have spnav_read return an error so the thread can terminate. But it continues blocking in the read system call. In Unix and Linux, you have to call shutdown from another thread to make read return (with an error.)

spnav_close should really call shutdown(fd, SHUT_RDWR) before calling close. In my app I work around it something like this:

void startSpnav()
{
    if (spnav_open() < 0) {
      if (1) cerr << "Can't open spnav\n";
    }
    else {
      spnavThread = std::thread(&spnavMain);
      atexit(stopSpnav);
    }
}

void stopSpnav()
{
  if (spnavThread.joinable()) {
    // This seems like the only way of getting the reading thread to notice that
    // the socket has been closed and exit nicely.
    shutdown(spnav_fd(), SHUT_RDWR);
    spnavThread.join();
  }
}

See complete code

jtsiomb commented 4 years ago

There's no spnav_read function in libspnav. Can you provide a minimal example program that reproduces the problem?

jtsiomb commented 4 years ago

Since it's unclear what this issue refers to and how to reproduce it, I'm closing it as invalid. If you can produce a minimal compilable example that reproduces the problem, please post it here and I will re-open it.