Initial commit
[remote/remote-mci.git] / mcs / FileDescriptor.h
blobabf2f9b7b41f102544e1c8703558ae6f66e96886
1 #ifndef _FILEDESCRIPTOR_H_
2 #define _FILEDESCRIPTOR_H_
4 #include "types.h"
5 #include "database.h"
6 #include "constants.h"
7 #include <stdlib.h>
8 #include <sys/poll.h>
9 #include <signal.h>
10 #include <sys/time.h>
11 #include <errno.h>
13 namespace remote { namespace mcs {
15 class FileDescriptor;
17 typedef std::map<int,FileDescriptor*> filedescriptorsbyfd_t;
19 /** Base class for handling socket connections through file descriptors.
21 **/
22 class FileDescriptor
24 public:
25 /** Main service loop using poll() system call to receive fd events**/
26 static void serviceLoop();
27 /** Handles an event on a specific file descriptor **/
28 virtual void handleEvent(short events) = 0;
29 /** Clean up and destroy a FileDescriptor object **/
30 virtual void destroy(bool silent=false);
31 protected:
32 void setTimeout(int secs);
33 static void clearTimeout();
34 FileDescriptor(int p_fd);
35 virtual ~FileDescriptor();
36 static void buildPollMap(pollfd* map);
37 static void timeoutHandler(int sig);
38 static void ignoreBrokenPipeSignals();
39 static filedescriptorsbyfd_t instances;
40 static int currentFd;
41 int fd;
47 #endif