Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef ADX_EPOLL_H
12 : #define ADX_EPOLL_H
13 : #include <cstdint>
14 : #include <memory>
15 : #include <vector>
16 : namespace Adx {
17 : using EpollHandle = uintptr_t;
18 : constexpr EpollHandle ADX_INVALID_HANDLE = -1;
19 : constexpr int32_t DEFAULT_EPOLL_SIZE = 128;
20 : constexpr int32_t DEFAULT_EPOLL_TIMEOUT = 500; // 500ms
21 :
22 : constexpr uint32_t ADX_EPOLL_CONN_IN = 1U << 0;
23 : constexpr uint32_t ADX_EPOLL_DATA_IN = 1U << 1;
24 : constexpr uint32_t ADX_EPOLL_HANG_UP = 1U << 2;
25 :
26 : struct EpollEvent {
27 : uint32_t events;
28 : EpollHandle data;
29 : };
30 :
31 : enum class EpollType {
32 : EPOLL_HDC,
33 : EPOLL_SOCK,
34 : NR_EPOLL
35 : };
36 :
37 : class AdxEpoll {
38 : public:
39 32 : AdxEpoll() : epMaxSize_(DEFAULT_EPOLL_SIZE) {}
40 32 : virtual ~AdxEpoll() {}
41 : virtual int32_t EpollCreate(const int32_t size) = 0;
42 : virtual int32_t EpollDestroy() = 0;
43 : virtual int32_t EpollCtl(EpollHandle target, EpollEvent &event, int32_t op) = 0;
44 : virtual int32_t EpollAdd(EpollHandle target, EpollEvent &event) = 0;
45 : virtual int32_t EpollDel(EpollHandle target, EpollEvent &event) = 0;
46 : virtual int32_t EpollWait(std::vector<EpollEvent> &events, int32_t size, int32_t timeout) = 0;
47 : virtual int32_t EpollErrorHandle() = 0;
48 : virtual int32_t EpollGetSize() = 0;
49 : protected:
50 : int32_t epMaxSize_;
51 : };
52 : }
53 : #endif
|