jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
780B

  1. #include <cerrno>
  2. #include <cstring>
  3. #include <stdexcept>
  4. #include <fcntl.h>
  5. #include <unistd.h>
  6. #include "JackALSARawMidiUtil.h"
  7. void
  8. Jack::CreateNonBlockingPipe(int *fds)
  9. {
  10. if (pipe(fds) == -1) {
  11. throw std::runtime_error(strerror(errno));
  12. }
  13. try {
  14. SetNonBlocking(fds[0]);
  15. SetNonBlocking(fds[1]);
  16. } catch (...) {
  17. close(fds[1]);
  18. close(fds[0]);
  19. throw;
  20. }
  21. }
  22. void
  23. Jack::DestroyNonBlockingPipe(int *fds)
  24. {
  25. close(fds[1]);
  26. close(fds[0]);
  27. }
  28. void
  29. Jack::SetNonBlocking(int fd)
  30. {
  31. int flags = fcntl(fd, F_GETFL);
  32. if (flags == -1) {
  33. throw std::runtime_error(strerror(errno));
  34. }
  35. if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
  36. throw std::runtime_error(strerror(errno));
  37. }
  38. }