Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Epoll Abstraction Layer (EAL)
0003  *
0004  * @file sys_epoll.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 
0035 /*---------------------------Includes-----------------------------------*/
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <time.h>
0039 
0040 #include <unistd.h>
0041 #include <stdarg.h>
0042 #include <ctype.h>
0043 #include <memory.h>
0044 #include <errno.h>
0045 #include <signal.h>
0046 #include <limits.h>
0047 #include <pthread.h>
0048 #include <string.h>
0049 
0050 #include <ndrstandard.h>
0051 #include <ndebug.h>
0052 #include <nstdutil.h>
0053 #include <limits.h>
0054 
0055 #include <sys_unix.h>
0056 #include <sys/epoll.h>
0057 
0058 
0059 /*---------------------------Externs------------------------------------*/
0060 /*---------------------------Macros-------------------------------------*/
0061 /*---------------------------Enums--------------------------------------*/
0062 /*---------------------------Typedefs-----------------------------------*/
0063 /*---------------------------Globals------------------------------------*/
0064 /*---------------------------Statics------------------------------------*/
0065 /*---------------------------Prototypes---------------------------------*/
0066 
0067 /**
0068  * not used by Linux epoll()
0069  * @param idx
0070  * @return 
0071  */
0072 expublic int ndrx_epoll_shallopenq(int idx)
0073 {
0074     return EXTRUE;
0075 }
0076 /**
0077  * Not used by Linux epoll()
0078  * @param qstr
0079  */
0080 expublic void ndrx_epoll_mainq_set(char *qstr)
0081 {
0082     return;
0083 }
0084 /**
0085  * Nothing to init for epoll()
0086  */
0087 expublic int ndrx_epoll_sys_init(void)
0088 {
0089     return EXSUCCEED;
0090 }
0091 
0092 /**
0093  * Not used by Linux epoll
0094  * @param svcnm
0095  * @param idx
0096  * @param mq_exits
0097  * @return 
0098  */
0099 expublic mqd_t ndrx_epoll_service_add(char *svcnm, int idx, mqd_t mq_exits)
0100 {
0101     return mq_exits;
0102 }
0103 
0104 /**
0105  * Not used by linux epoll
0106  * @return 
0107  */
0108 expublic int ndrx_epoll_shmdetach(void)
0109 {
0110     return EXSUCCEED;
0111 }
0112 
0113 /**
0114  * Not used by Linux epoll
0115  * @param force
0116  * @return 
0117  */
0118 expublic int ndrx_epoll_down(int force)
0119 {
0120     return EXSUCCEED;
0121 }
0122 
0123 /**
0124  * Nothing to un-init for epoll()
0125  */
0126 expublic void ndrx_epoll_sys_uninit(void)
0127 {
0128     return;
0129 }
0130 
0131 /**
0132  * Return the compiled poll mode
0133  * @return 
0134  */
0135 expublic char * ndrx_epoll_mode(void)
0136 {
0137     static char *mode = "epoll";
0138     
0139     return mode;
0140 }
0141 
0142 /**
0143  * Wrapper for epoll_ctl, for standard file descriptors
0144  * @param epfd
0145  * @param op
0146  * @param fd
0147  * @param event
0148  * @return 
0149  */
0150 expublic inline int ndrx_epoll_ctl(int epfd, int op, int fd, struct ndrx_epoll_event *event)
0151 {
0152     return epoll_ctl(epfd, op, fd, (struct epoll_event *) event);
0153 }
0154 
0155 /**
0156  * epoll_ctl for Posix queue descriptors
0157  * @param epfd
0158  * @param op
0159  * @param fd
0160  * @param event
0161  * @return 
0162  */
0163 expublic inline int ndrx_epoll_ctl_mq(int epfd, int op, mqd_t fd, struct ndrx_epoll_event *event)
0164 {
0165     return epoll_ctl(epfd, op, fd, (struct epoll_event *) event);
0166 }
0167 
0168 /**
0169  * Wrapper for epoll_create
0170  * @param size
0171  * @return 
0172  */
0173 expublic inline int ndrx_epoll_create(int size)
0174 {
0175     return epoll_create(size);
0176 }
0177 
0178 /**
0179  * Close Epoll set.
0180  */
0181 expublic inline int ndrx_epoll_close(int fd)
0182 {
0183     return close(fd);
0184 }
0185 
0186 /**
0187  * Wrapper for epoll_wait
0188  * @param epfd
0189  * @param events
0190  * @param maxevents
0191  * @param timeout
0192  * @return 
0193  */
0194 expublic inline int ndrx_epoll_wait(int epfd, struct ndrx_epoll_event *events, 
0195         int maxevents, int timeout, char **buf, int *buf_len)
0196 {
0197     *buf_len = EXFAIL;
0198     return epoll_wait(epfd, (struct epoll_event *) events, maxevents, timeout);
0199 }
0200 
0201 /**
0202  * Return errno for ndrx_poll() operation
0203  * @return 
0204  */
0205 expublic inline int ndrx_epoll_errno(void)
0206 {
0207     return errno;
0208 }
0209 
0210 /**
0211  * Wrapper for strerror
0212  * @param err
0213  * @return 
0214  */
0215 expublic inline char * ndrx_poll_strerror(int err)
0216 {
0217     return strerror(err);
0218 }
0219 
0220 /* vim: set ts=4 sw=4 et smartindent: */