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_maxfd(0), a_ptrTimeout(NULL), a_minfd(INT_MAX) {
38 void setTimeout(const Millisecond &timeout) throw();
40 void waitMessage() throw(RuntimeException);
42 bool isEmpty() const throw() { return a_pollr <= 0; }
43 void clear() throw() { a_maxfd = 0; a_minfd = INT_MAX; FD_ZERO(&a_fdmask); FD_ZERO(&a_fdset);}
44 void insert(const int fd) throw();
45 void erase(const int fd) throw();
55 timeval* a_ptrTimeout;
57 static int select(const int maxfd, fd_set* fdset, timeval* timeout)
58 throw(RuntimeException) {
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) throw() { return (n1 < n2) ? n1 : n2; }