1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_comm_internal_Poll_hpp
10 #define anna_comm_internal_Poll_hpp
16 #include <anna/config/defines.hpp>
17 #include <anna/core/util/defines.hpp>
18 #include <anna/core/RuntimeException.hpp>
19 #include <anna/core/functions.hpp>
26 Clase que asegura que el comm::Reader no se quedara esperando indefinidamente a
27 que un determinado mensaje haya sido tratado y mantiene la integridad de forma
28 ya que asegura que el tratamiento de un mensaje solo tendra un unico signal enviado
29 hacia el comm::Reader.
33 Poll() : a_ptrTimeout(NULL), a_minfd(INT_MAX), a_maxfd(0) {
38 void setTimeout(const Millisecond &timeout) ;
40 void waitMessage() noexcept(false);
42 bool isEmpty() const { return a_pollr <= 0; }
43 void clear() { a_maxfd = 0; a_minfd = INT_MAX; FD_ZERO(&a_fdmask); FD_ZERO(&a_fdset);}
44 void insert(const int fd) ;
45 void erase(const int fd) ;
50 timeval* a_ptrTimeout;
57 static int select(const int maxfd, fd_set* fdset, timeval* timeout)
62 result = ::select(maxfd + 1, fdset, NULL, NULL, timeout);
63 } while(result == -1 && errno == EINTR);
67 throw RuntimeException("Error en anna::comm::Poll::select", xerrno, ANNA_FILE_LOCATION);
73 static int min(const Millisecond &n1, const Millisecond &n2) { return (n1 < n2) ? n1 : n2; }