class Connection, Network, Port: select() replaced by ppoll().

This commit is contained in:
Roland Jax
2014-11-13 16:31:32 +01:00
parent 5e07f0152d
commit baf60895ef
5 changed files with 51 additions and 48 deletions
+13 -7
View File
@@ -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
View File
@@ -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.
*/