You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.2 KiB

13 years ago
#ifndef POLL_HPP
#define POLL_HPP
#include "StreamConnection.hpp"
13 years ago
#include <poll.h>
#include <map>
13 years ago
13 years ago
class Poll
{
public:
Poll( StreamConnection *connection,
const nfds_t maxClient = 10,
const int timeOut = 10 * 1000 ); // 10sec
virtual ~Poll();
void startPolling();
void stopPolling();
bool isPolling() const;
protected:
// can be overriden: behaviour alters in server/client
virtual void acceptClient();
// can be overriden: behaviour alters in server/client
virtual void handleClient( const int socket );
13 years ago
private:
Poll(const Poll&);
Poll& operator=(const Poll&);
typedef typename std::map< int, StreamConnection* > ConnectionMap;
// can be overriden: behaviour alters in server/client
virtual void removeTimeoutedConnections();
ConnectionMap::iterator removeConnection(int socket, ConnectionMap::iterator it);
bool addFd( const int socket, const short events );
bool removeFd( const int socket );
int m_timeOut;
StreamConnection *m_connection;
volatile bool m_polling;
ConnectionMap m_connections;
nfds_t m_maxclients;
pollfd *m_fds;
nfds_t m_num_of_fds;
13 years ago
};
#endif // POLL_HPP