ffead.server.doc
SelEpolKqEvPrt.h
1 /*
2  Copyright 2009-2013, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * SelEpolKqEvPrt.h
18  *
19  * Created on: 30-Dec-2012
20  * Author: sumeetc
21  */
22 
23 #ifndef SELEPOLKQEVPRT_H_
24 #define SELEPOLKQEVPRT_H_
25 #include <sys/types.h>
26 #include "AppDefines.h"
27 #include "Logger.h"
28 #include "cstring"
29 #include <fcntl.h>
30 #include <sys/time.h>
31 #define MAXDESCRIPTORS 1024
32 
34  Logger logger;
35  int mode;
36  int sockfd;
37  int curfds;
38  #ifdef USE_SELECT
39  fd_set master; // master file descriptor list
40  fd_set read_fds; // temp file descriptor list for select()
41  int fdmax;
42  #endif
43  #ifdef USE_EPOLL
44  struct epoll_event ev;
45  struct epoll_event events[MAXDESCRIPTORS];
46  int epoll_handle;
47  #endif
48  #ifdef USE_KQUEUE
49  int kq;
50  struct kevent evlist[MAXDESCRIPTORS];
51  struct kevent change;
52  #endif
53  #ifdef USE_DEVPOLL
54  int dev_poll_fd;
55  struct pollfd polled_fds[MAXDESCRIPTORS];
56  #endif
57  #ifdef USE_EVPORT
58  int port;
59  port_event_t evlist[MAXDESCRIPTORS];
60  #endif
61  #ifdef USE_POLL
62  nfds_t nfds;
63  struct pollfd *polled_fds;
64  #endif
65 public:
67  virtual ~SelEpolKqEvPrt();
68  void initialize(int sockfd);
69  int getEvents();
70  int getDescriptor(int index);
71  bool isListeningDescriptor(int descriptor);
72  bool registerForEvent(int descriptor);
73  bool unRegisterForEvent(int descriptor);
74  void reRegisterServerSock();
75 };
76 
77 #endif /* SELEPOLKQEVPRT_H_ */