1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SYS_EPOLL_H 17 #define SYS_EPOLL_H 18 19 #include "nstackx_common_header.h" 20 21 typedef struct EpollDescStr { 22 int32_t recvFd; 23 int32_t sendFd; 24 } *EpollDesc; 25 26 struct EpollEvent { 27 uint32_t op; 28 uint32_t events; 29 void *ptr; 30 #ifdef NSTACKX_DEBUG 31 uint32_t evtSeq; 32 #endif 33 }; 34 35 typedef int32_t TaskDesc; 36 37 #ifndef EPOLL_CTL_ADD 38 #define EPOLL_CTL_ADD 1 39 #define EPOLL_CTL_DEL 2 40 #define EPOLL_CTL_MOD 3 41 #endif 42 43 #define EPOLL_CTL_RUN ((EPOLL_CTL_MOD) + 1) 44 45 #define INVALID_EPOLL_DESC (NULL) 46 #define INVALID_TASK_DESC (-1) 47 48 #define REPRESENT_EPOLL_DESC(epollfd) ((epollfd)->recvFd) 49 50 int32_t CreateEpollFdPair(struct EpollDescStr *epollfd); 51 int32_t RunEpollTask(void *task, uint32_t events); 52 void CloseEpollDescInner(EpollDesc epollfd); 53 void CloseDescClearEpollPtr(int32_t desc); 54 IsEpollDescValid(EpollDesc epollfd)55static inline bool IsEpollDescValid(EpollDesc epollfd) 56 { 57 return (epollfd != INVALID_EPOLL_DESC); 58 } 59 IsEpollDescEqual(EpollDesc epollfd1,EpollDesc epollfd2)60static inline bool IsEpollDescEqual(EpollDesc epollfd1, EpollDesc epollfd2) 61 { 62 return (epollfd1 == epollfd2); 63 } 64 CloseEpollDesc(EpollDesc epollfd)65static inline void CloseEpollDesc(EpollDesc epollfd) 66 { 67 CloseEpollDescInner(epollfd); 68 } 69 70 void EpollEventPtrInit(void); 71 72 #endif // SYS_EPOLL_H 73