class Connection, Network, Port: select() replaced by ppoll().
This commit is contained in:
+13
-7
@@ -24,6 +24,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <poll.h>
|
||||
|
||||
|
||||
namespace libebus
|
||||
@@ -68,18 +69,23 @@ ssize_t Device::recvBytes(const long timeout, size_t maxCount)
|
||||
return -1; // TODO RESULT_ERR_DEVICE
|
||||
|
||||
if (timeout > 0) {
|
||||
fd_set readfds;
|
||||
struct timeval tdiff;
|
||||
int ret, nfds = 1;
|
||||
struct pollfd fds[nfds];
|
||||
struct timespec tdiff;
|
||||
|
||||
// set select timeout
|
||||
tdiff.tv_sec = 0;
|
||||
tdiff.tv_usec = timeout;
|
||||
tdiff.tv_nsec = timeout*1000;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(m_fd, &readfds);
|
||||
memset(fds, 0, sizeof(fds));
|
||||
|
||||
if (select(m_fd + 1, &readfds, NULL, NULL, &tdiff) != 1)
|
||||
return -2; // TODO RESULT_ERR_TIMEOUT
|
||||
fds[0].fd = m_fd;
|
||||
fds[0].events = POLLIN;
|
||||
|
||||
ret = ppoll(fds, nfds, &tdiff, NULL);
|
||||
|
||||
if (ret == -1) return -1; // TODO RESULT_ERR_DEVICE
|
||||
if (ret == 0) return -2; // TODO RESULT_ERR_TIMEOUT
|
||||
}
|
||||
|
||||
if (maxCount > sizeof(m_buffer))
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public:
|
||||
|
||||
/**
|
||||
* @brief recvBytes read bytes from opened file descriptor.
|
||||
* @param timeout max time out for new input data.
|
||||
* @param timeoutmax time for new input data [usec].
|
||||
* @param maxCount max size of receive buffer.
|
||||
* @return number of read bytes or -1 if an error has occured.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user