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 SOCKET_SERVER_H
17 #define SOCKET_SERVER_H
18 
19 #include <memory>
20 #include <sys/socket.h>
21 #include <sys/types.h>
22 #include <sys/un.h>
23 #include <string>
24 #include <chrono>
25 
26 #include "hilog_common.h"
27 #include "socket_client.h"
28 
29 namespace OHOS {
30 namespace HiviewDFX {
31 class SocketServer {
32 public:
33     SocketServer(const std::string& _socketName, uint32_t _socketType);
34     virtual ~SocketServer();
35     int Init();
36     int Recv(void *buffer, unsigned int bufferLen, int flags = MSG_PEEK);
37     int RecvMsg(struct msghdr *hdr, int flags = 0);
38     int Listen(unsigned int backlog);
39     int Poll(short inEvent, short& outEvent, const std::chrono::milliseconds& timeout);
40     int Accept();
41 private:
42     int socketHandler;
43     uint32_t socketType;
44     sockaddr_un serverAddr;
45     std::string socketName;
46 };
47 } // namespace HiviewDFX
48 } // namespace OHOS
49 #endif /* SOCKET_SERVER_H */
50