CAN adopted, Linux work

This commit is contained in:
2022-11-07 18:07:26 +03:00
parent 6da1ec5acf
commit fffaf0726d
4 changed files with 29 additions and 14 deletions

View File

@@ -28,7 +28,6 @@
# include <fcntl.h>
# include <sys/ioctl.h>
#endif
#include "piincludes_p.h"
#include "pistring.h"
@@ -45,7 +44,7 @@ void PIWaitEvent::create() {
piCout << "Error with CreateEventA:" << errorString();
}
#else
for (int i = 0; i < sizeof(fds); ++i) memset(&(fds[i]), 0, sizeof(fds[i]));
for (int i = 0; i < 3; ++i) memset(&(fds[i]), 0, sizeof(fds[i]));
if (::pipe(pipe_fd) < 0) {
piCout << "Error with pipe:" << errorString();
} else {
@@ -62,7 +61,7 @@ void PIWaitEvent::destroy() {
event = NULL;
}
#else
for (int i = 0; i < sizeof(pipe_fd); ++i) {
for (int i = 0; i < 2; ++i) {
if (pipe_fd[i] != 0) {
::close(pipe_fd[i]);
pipe_fd[i] = 0;
@@ -82,7 +81,7 @@ bool PIWaitEvent::wait(int fd, CheckRole role) {
if (fd == -1) return false;
int nfds = piMaxi(pipe_fd[ReadEnd], fd) + 1;
int fd_index = role;
for (int i = 0; i < sizeof(fds); ++i) FD_ZERO(&(fds[i]));
for (int i = 0; i < 3; ++i) FD_ZERO(&(fds[i]));
FD_SET(pipe_fd[ReadEnd], &(fds[CheckRead]));
FD_SET(fd, &(fds[CheckExeption]));
if (fd_index != CheckExeption) FD_SET(fd, &(fds[fd_index]));
@@ -116,5 +115,9 @@ bool PIWaitEvent::isCreate() const {
void * PIWaitEvent::getEvent() const {
#ifdef WINDOWS
return event;
#else
return nullptr;
#endif
}

View File

@@ -35,19 +35,17 @@ class PIWaitEvent {
public:
~PIWaitEvent();
void create();
void destroy();
enum CheckRole { // UNIX only
CheckRead,
CheckWrite,
CheckExeption
};
bool wait(int fd = -1, CheckRole role = CheckRead);
void create();
void destroy();
bool wait(int fd = -1, CheckRole role = CheckRead);
void interrupt();
bool isCreate() const;
void * getEvent() const; // WINDOWS only
private: