Jack2  1.9.10
JackALSARawMidiUtil.cpp
00001 #include <cerrno>
00002 #include <cstring>
00003 #include <stdexcept>
00004 
00005 #include <fcntl.h>
00006 #include <unistd.h>
00007 
00008 #include "JackALSARawMidiUtil.h"
00009 
00010 void
00011 Jack::CreateNonBlockingPipe(int *fds)
00012 {
00013     if (pipe(fds) == -1) {
00014         throw std::runtime_error(strerror(errno));
00015     }
00016     try {
00017         SetNonBlocking(fds[0]);
00018         SetNonBlocking(fds[1]);
00019     } catch (...) {
00020         close(fds[1]);
00021         close(fds[0]);
00022         throw;
00023     }
00024 }
00025 
00026 void
00027 Jack::DestroyNonBlockingPipe(int *fds)
00028 {
00029     close(fds[1]);
00030     close(fds[0]);
00031 }
00032 
00033 void
00034 Jack::SetNonBlocking(int fd)
00035 {
00036     int flags = fcntl(fd, F_GETFL);
00037     if (flags == -1) {
00038         throw std::runtime_error(strerror(errno));
00039     }
00040     if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
00041         throw std::runtime_error(strerror(errno));
00042     }
00043 }