pip micro disable piintrospection piwaitevent
PIP_NO_SOCET
This commit is contained in:
@@ -18,18 +18,19 @@
|
||||
*/
|
||||
|
||||
#include "piwaitevent_p.h"
|
||||
#ifdef WINDOWS
|
||||
#ifndef MICRO_PIP
|
||||
# ifdef WINDOWS
|
||||
// # ifdef _WIN32_WINNT
|
||||
// # undef _WIN32_WINNT
|
||||
// # define _WIN32_WINNT 0x0600
|
||||
// # endif
|
||||
# include <synchapi.h>
|
||||
#else
|
||||
# include <errno.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
#include "pistring.h"
|
||||
# include <synchapi.h>
|
||||
# else
|
||||
# include <errno.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/ioctl.h>
|
||||
# endif
|
||||
# include "pistring.h"
|
||||
|
||||
|
||||
PIWaitEvent::~PIWaitEvent() {
|
||||
@@ -39,12 +40,12 @@ PIWaitEvent::~PIWaitEvent() {
|
||||
|
||||
void PIWaitEvent::create() {
|
||||
destroy();
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
||||
if (!event) {
|
||||
piCout << "Error with CreateEventA:" << errorString();
|
||||
}
|
||||
#else
|
||||
# else
|
||||
for (int i = 0; i < 3; ++i)
|
||||
piZeroMemory(fds[i]);
|
||||
if (::pipe(pipe_fd) < 0) {
|
||||
@@ -53,34 +54,34 @@ void PIWaitEvent::create() {
|
||||
fcntl(pipe_fd[ReadEnd], F_SETFL, O_NONBLOCK);
|
||||
fcntl(pipe_fd[WriteEnd], F_SETFL, O_NONBLOCK);
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void PIWaitEvent::destroy() {
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
if (event) {
|
||||
CloseHandle(event);
|
||||
event = NULL;
|
||||
}
|
||||
#else
|
||||
# else
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
if (pipe_fd[i] != 0) {
|
||||
::close(pipe_fd[i]);
|
||||
pipe_fd[i] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
bool PIWaitEvent::wait(int fd, CheckRole role) {
|
||||
if (!isCreate()) return false;
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
DWORD ret = WaitForSingleObjectEx(event, INFINITE, TRUE);
|
||||
ResetEvent(event);
|
||||
if (ret == WAIT_IO_COMPLETION || ret == WAIT_FAILED) return false;
|
||||
#else
|
||||
# else
|
||||
if (fd == -1) return false;
|
||||
int nfds = piMaxi(pipe_fd[ReadEnd], fd) + 1;
|
||||
int fd_index = role;
|
||||
@@ -97,18 +98,18 @@ bool PIWaitEvent::wait(int fd, CheckRole role) {
|
||||
if (sr == EBADF || sr == EINTR) return false;
|
||||
if (FD_ISSET(fd, &(fds[CheckExeption]))) return true;
|
||||
return FD_ISSET(fd, &(fds[fd_index]));
|
||||
#endif
|
||||
# endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PIWaitEvent::sleep(int us) {
|
||||
if (!isCreate()) return false;
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
DWORD ret = WaitForSingleObjectEx(event, us / 1000, TRUE);
|
||||
ResetEvent(event);
|
||||
return ret == WAIT_TIMEOUT;
|
||||
#else
|
||||
# else
|
||||
int nfds = pipe_fd[ReadEnd] + 1;
|
||||
FD_ZERO(&(fds[CheckRead]));
|
||||
FD_SET(pipe_fd[ReadEnd], &(fds[CheckRead]));
|
||||
@@ -120,34 +121,36 @@ bool PIWaitEvent::sleep(int us) {
|
||||
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0)
|
||||
;
|
||||
return ret == 0;
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void PIWaitEvent::interrupt() {
|
||||
if (!isCreate()) return;
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
SetEvent(event);
|
||||
#else
|
||||
# else
|
||||
auto _r = ::write(pipe_fd[WriteEnd], "", 1);
|
||||
NO_UNUSED(_r);
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
bool PIWaitEvent::isCreate() const {
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
return event;
|
||||
#else
|
||||
# else
|
||||
return pipe_fd[ReadEnd] != 0;
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void * PIWaitEvent::getEvent() const {
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
return event;
|
||||
#else
|
||||
# else
|
||||
return nullptr;
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif // MICRO_PIP
|
||||
|
||||
Reference in New Issue
Block a user