Add checks to configure.ac for pselect() and ppoll().

This commit is contained in:
Roland Jax
2014-11-21 19:10:02 +01:00
parent 3ddd829dc7
commit 6b19680b61
3 changed files with 119 additions and 10 deletions
+22 -2
View File
@@ -17,6 +17,10 @@
* along with ebusd. If not, see http://www.gnu.org/licenses/.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "port.h"
#include <cstdlib>
#include <cstring>
@@ -24,7 +28,10 @@
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef HAVE_PPOLL
#include <poll.h>
#endif
bool Device::isOpen()
{
@@ -64,20 +71,33 @@ ssize_t Device::recvBytes(const long timeout, size_t maxCount)
return -1; // TODO RESULT_ERR_DEVICE
if (timeout > 0) {
int ret, nfds = 1;
struct pollfd fds[nfds];
int ret;
struct timespec tdiff;
// set select timeout
tdiff.tv_sec = 0;
tdiff.tv_nsec = timeout*1000;
#ifdef HAVE_PPOLL
int nfds = 1;
struct pollfd fds[nfds];
memset(fds, 0, sizeof(fds));
fds[0].fd = m_fd;
fds[0].events = POLLIN;
ret = ppoll(fds, nfds, &tdiff, NULL);
#else
#ifdef HAVE_PSELECT
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(m_fd, &readfds);
ret = pselect(m_fd + 1, &readfds, NULL, NULL, &tdiff, NULL);
#endif
#endif
if (ret == -1) return -1; // TODO RESULT_ERR_DEVICE
if (ret == 0) return -2; // TODO RESULT_ERR_TIMEOUT