• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

P_UnixPollDescriptor.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026   UnixPollDescriptor.h
00027 
00028 
00029 *****************************************************************************/
00030 #ifndef __P_UNIXPOLLDESCRIPTOR_H__
00031 #define __P_UNIXPOLLDESCRIPTOR_H__
00032 
00033 #include "libts.h"
00034 
00035 #if TS_USE_KQUEUE
00036 #include <sys/event.h>
00037 #define INK_EVP_IN    0x001
00038 #define INK_EVP_PRI   0x002
00039 #define INK_EVP_OUT   0x004
00040 #define INK_EVP_ERR   0x010
00041 #define INK_EVP_HUP   0x020
00042 #endif
00043 
00044 #define POLL_DESCRIPTOR_SIZE 32768
00045 
00046 typedef struct pollfd Pollfd;
00047 
00048 struct PollDescriptor
00049 {
00050   int result;                   // result of poll
00051 #if TS_USE_EPOLL
00052   int epoll_fd;
00053   int nfds;                     // actual number
00054   Pollfd pfd[POLL_DESCRIPTOR_SIZE];
00055   struct epoll_event ePoll_Triggered_Events[POLL_DESCRIPTOR_SIZE];
00056 #endif
00057 #if TS_USE_KQUEUE
00058   int kqueue_fd;
00059 #endif
00060 #if TS_USE_PORT
00061   int port_fd;
00062 #endif
00063 
00064 #if TS_USE_EPOLL
00065 #define get_ev_port(a) ((a)->epoll_fd)
00066 #define get_ev_events(a,x) ((a)->ePoll_Triggered_Events[(x)].events)
00067 #define get_ev_data(a,x) ((a)->ePoll_Triggered_Events[(x)].data.ptr)
00068 #define ev_next_event(a,x)
00069 #endif
00070 
00071 #if TS_USE_KQUEUE
00072   struct kevent kq_Triggered_Events[POLL_DESCRIPTOR_SIZE];
00073   /* we define these here as numbers, because for kqueue mapping them to a combination of
00074  * filters / flags is hard to do. */
00075 #define get_ev_port(a) ((a)->kqueue_fd)
00076 #define get_ev_events(a,x) ((a)->kq_event_convert((a)->kq_Triggered_Events[(x)].filter, (a)->kq_Triggered_Events[(x)].flags))
00077 #define get_ev_data(a,x) ((a)->kq_Triggered_Events[(x)].udata)
00078   int kq_event_convert(int16_t event, uint16_t flags)
00079   {
00080     int r = 0;
00081 
00082     if (event == EVFILT_READ) {
00083       r |= INK_EVP_IN;
00084     }
00085     else if (event == EVFILT_WRITE) {
00086       r |= INK_EVP_OUT;
00087     }
00088 
00089     if (flags & EV_EOF) {
00090       r |= INK_EVP_HUP;
00091     }
00092     return r;
00093   }
00094 #define ev_next_event(a,x)
00095 #endif
00096 
00097 #if TS_USE_PORT
00098   port_event_t Port_Triggered_Events[POLL_DESCRIPTOR_SIZE];
00099 #define get_ev_port(a) ((a)->port_fd)
00100 #define get_ev_events(a,x) ((a)->Port_Triggered_Events[(x)].portev_events)
00101 #define get_ev_data(a,x) ((a)->Port_Triggered_Events[(x)].portev_user)
00102 #define get_ev_odata(a,x) ((a)->Port_Triggered_Events[(x)].portev_object)
00103 #define ev_next_event(a,x)
00104 #endif
00105 
00106   Pollfd *alloc()
00107   {
00108 #if TS_USE_EPOLL
00109     // XXX : We need restrict max size based on definition.
00110     if (nfds >= POLL_DESCRIPTOR_SIZE) {
00111       nfds = 0;
00112     }
00113     return &pfd[nfds++];
00114 #else
00115     return 0;
00116 #endif
00117   }
00118   PollDescriptor *init()
00119   {
00120     result = 0;
00121 #if TS_USE_EPOLL
00122     nfds = 0;
00123     epoll_fd = epoll_create(POLL_DESCRIPTOR_SIZE);
00124     memset(ePoll_Triggered_Events, 0, sizeof(ePoll_Triggered_Events));
00125     memset(pfd, 0, sizeof(pfd));
00126 #endif
00127 #if TS_USE_KQUEUE
00128     kqueue_fd = kqueue();
00129     memset(kq_Triggered_Events, 0, sizeof(kq_Triggered_Events));
00130 #endif
00131 #if TS_USE_PORT
00132     port_fd = port_create();
00133     memset(Port_Triggered_Events, 0, sizeof(Port_Triggered_Events));
00134 #endif
00135     return this;
00136   }
00137   PollDescriptor() {
00138     init();
00139   }
00140 };
00141 
00142 #endif

Generated by  doxygen 1.7.1