Jack2: JackALSARawMidiUtil.cpp Source File

Jack2 1.9.12

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