• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 UDS_SOCKET_H
17 #define UDS_SOCKET_H
18 
19 #include <sys/epoll.h>
20 #include <sys/socket.h>
21 #include <unistd.h>
22 
23 #include "circle_stream_buffer.h"
24 #include "net_packet.h"
25 
26 namespace OHOS {
27 namespace MMI {
28 class UDSSocket {
29 public:
30     UDSSocket();
31     DISALLOW_COPY_AND_MOVE(UDSSocket);
32     virtual ~UDSSocket();
33     using PacketCallBackFun = std::function<void(NetPacket&)>;
34 
35     int32_t EpollCreate(int32_t size);
36     int32_t EpollCtl(int32_t fd, int32_t op, struct epoll_event &event, int32_t epollFd = -1);
37     int32_t EpollWait(struct epoll_event &events, int32_t maxevents, int32_t timeout, int32_t epollFd = -1);
38     void OnReadPackets(CircleStreamBuffer &buf, PacketCallBackFun callbackFun);
39     void EpollClose();
40     void Close();
41 
GetFd()42     int32_t GetFd() const
43     {
44         return fd_;
45     }
GetEpollFd()46     int32_t GetEpollFd() const
47     {
48         return epollFd_;
49     }
50 
51 protected:
52     int32_t fd_ { -1 };
53     int32_t epollFd_ { -1 };
54 };
55 } // namespace MMI
56 } // namespace OHOS
57 #endif // UDS_SOCKET_H