11 #include <mach-o/dyld.h> 16 char buffer[512] = {};
17 strerror_r(code, buffer,
sizeof(buffer));
22 int flags = fcntl(fd, F_GETFL, 0);
24 if (bNonBlocking) flags2 |= O_NONBLOCK;
25 else flags2 &= ~O_NONBLOCK;
26 if (flags2 != flags) fcntl(fd, F_SETFL, flags2);
30 int flags = fcntl(fd, F_GETFD);
32 if (bCloseOnExec) flags2 |= FD_CLOEXEC;
33 else flags2 &= ~FD_CLOEXEC;
34 if (flags != flags2) fcntl(fd, F_SETFD, flags2);
42 #if defined(__linux__) && defined(O_CLOEXEC) 43 if (pipe2(fd, bInheritable ? 0 : O_CLOEXEC) < 0)
throw exception_nix();
66 uint64_t temp = (uint64_t) floor( timeSeconds * 1000000.0 + 0.5);
67 tv.tv_usec = (uint32_t) (temp % 1000000);
68 tv.tv_sec = (uint32_t) (temp / 1000000);
72 return (
double)in.tv_sec + (double)in.tv_usec / 1000000.0;
82 return m_fds.find( fd ) != m_fds.end();
89 for(
auto i = other.
m_fds.begin(); i != other.
m_fds.end(); ++ i ) {
99 if (timeOutSeconds < 0) {
101 }
else if (timeOutSeconds == 0) {
107 return Select_( ms );
114 const size_t count = total.
m_fds.size();
118 for(
auto i = total.
m_fds.begin(); i != total.
m_fds.end(); ++ i ) {
120 auto & f = v[walk++];
122 f.events = (Reads[fd] ? POLLIN : 0) | (Writes[fd] ? POLLOUT : 0);
125 int status = poll(v.
get_ptr(), (int)count, timeOutMS);
128 Reads.clear(); Writes.clear(); Errors.clear();
131 for(walk = 0; walk < count; ++walk) {
133 if (f.revents & POLLIN) Reads += f.fd;
134 if (f.events & POLLOUT) Writes += f.fd;
135 if (f.events & POLLERR) Errors += f.fd;
151 return sel.
Select( timeOutSeconds ) > 0;
155 return sel.
Select( timeOutSeconds ) > 0;
173 write( m_fd[1], &dummy, 1);
179 if (
read(m_fd[0], &dummy, 1 ) != 1)
break;
185 return fdWaitRead( m_fd[0], p_timeout_seconds );
188 return fdWaitRead( p_event, p_timeout_seconds );
194 int state = sel.
Select( timeout );
196 if (state == 0)
return 0;
197 if (sel.
Reads[ h1 ] )
return 1;
198 if (sel.
Reads[ h2 ] )
return 2;
212 gettimeofday(&tv, NULL);
220 ssize_t rv = (size_t) readlink(path, buffer.
get_ptr(), l);
221 if (rv < 0)
return false;
222 if ((
size_t)rv <= l) {
233 _NSGetExecutablePath(NULL, &len);
235 _NSGetExecutablePath(temp.
get_ptr(), &len);
239 return nixReadSymLink( strOut, PFC_string_formatter() <<
"/proc/" << (
unsigned) getpid() <<
"/exe");
246 randomData = open(
"/dev/urandom", O_RDONLY);
251 throw std::runtime_error(
"getRandomData failure");
255 #ifndef __APPLE__ // for Apple they are implemented in Obj-C
void read(const service_ptr_t< file > &p_file, abort_callback &p_abort, pfc::string_base &p_out, bool &is_utf8)
int Select_(int timeOutMS)
void setNonBlocking(int fd, bool bNonBlocking)
bool nixSelfProcessPath(string_base &strOut)
const t_item * get_ptr() const
void setCloseOnExec(int fd, bool bCloseOnExec)
void set_state(bool state)
void nixGetRandomData(void *outPtr, size_t outBytes)
void nixFormatError(string_base &str, int code)
bool nixReadSymLink(string_base &strOut, const char *path)
void uSleepSeconds(double seconds, bool)
void set_size(t_size p_size)
bool fdWaitRead(int fd, double timeOutSeconds)
t_int32 rint32(double p_val)
bool fdWaitWrite(int fd, double timeOutSeconds)
void write(const service_ptr_t< file > &p_file, abort_callback &p_abort, const char *p_string, bool is_utf8)
static int g_twoEventWait(nix_event &ev1, nix_event &ev2, double timeout)
timeval makeTimeVal(double timeSeconds)
void createPipe(int fd[2], bool bInheritable)
void set_size_discard(t_size p_size)
void setInheritable(int fd, bool bInheritable)
static bool g_wait_for(int p_event, double p_timeout_seconds)
void nixSleep(double seconds)
bool wait_for(double p_timeout_seconds)
double importTimeval(const timeval &in)