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 NSTACKX_EPOLL_H 17 #define NSTACKX_EPOLL_H 18 19 #include "sys_epoll.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #ifndef EPOLLIN 26 #define EPOLLIN 0x00000001U 27 #endif 28 29 #ifndef EPOLLOUT 30 #define EPOLLOUT 0x00000004U 31 #endif 32 33 #ifndef EPOLLERR 34 #define EPOLLERR 0x00000008U 35 #endif 36 37 #ifndef EPOLLHUP 38 #define EPOLLHUP 0x00000010U 39 #endif 40 41 typedef void (*TaskHandle)(void *arg); 42 43 typedef struct { 44 EpollDesc epollfd; 45 TaskDesc taskfd; 46 TaskHandle readHandle; 47 TaskHandle writeHandle; 48 TaskHandle errorHandle; 49 void *ptr; 50 uint64_t count; 51 } EpollTask; 52 53 NSTACKX_EXPORT int32_t RegisterEpollTask(EpollTask *task, uint32_t events); 54 NSTACKX_EXPORT int32_t DeRegisterEpollTask(EpollTask *task); 55 NSTACKX_EXPORT int32_t RefreshEpollTask(EpollTask *task, uint32_t events); 56 NSTACKX_EXPORT EpollDesc CreateEpollDesc(void); 57 NSTACKX_EXPORT int32_t EpollLoop(EpollDesc epollfd, int32_t timeout); 58 static inline bool IsEpollDescValid(EpollDesc epollfd); 59 static inline bool IsEpollDescEqual(EpollDesc epollfd1, EpollDesc epollfd2); 60 static inline void CloseEpollDesc(EpollDesc epollfd); 61 62 #ifdef __cplusplus 63 } 64 #endif 65 66 #endif // NSTACKX_EPOLL_H 67