12498b56bSopenharmony_ci/*
22498b56bSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
32498b56bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
42498b56bSopenharmony_ci * you may not use this file except in compliance with the License.
52498b56bSopenharmony_ci * You may obtain a copy of the License at
62498b56bSopenharmony_ci *
72498b56bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
82498b56bSopenharmony_ci *
92498b56bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
102498b56bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
112498b56bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
122498b56bSopenharmony_ci * See the License for the specific language governing permissions and
132498b56bSopenharmony_ci * limitations under the License.
142498b56bSopenharmony_ci */
152498b56bSopenharmony_ci
162498b56bSopenharmony_ci#ifndef SOCKET_SERVER_H
172498b56bSopenharmony_ci#define SOCKET_SERVER_H
182498b56bSopenharmony_ci
192498b56bSopenharmony_ci#include <memory>
202498b56bSopenharmony_ci#include <sys/socket.h>
212498b56bSopenharmony_ci#include <sys/types.h>
222498b56bSopenharmony_ci#include <sys/un.h>
232498b56bSopenharmony_ci#include <string>
242498b56bSopenharmony_ci#include <chrono>
252498b56bSopenharmony_ci
262498b56bSopenharmony_ci#include "hilog_common.h"
272498b56bSopenharmony_ci#include "socket_client.h"
282498b56bSopenharmony_ci
292498b56bSopenharmony_cinamespace OHOS {
302498b56bSopenharmony_cinamespace HiviewDFX {
312498b56bSopenharmony_ciclass SocketServer {
322498b56bSopenharmony_cipublic:
332498b56bSopenharmony_ci    SocketServer(const std::string& _socketName, uint32_t _socketType);
342498b56bSopenharmony_ci    virtual ~SocketServer();
352498b56bSopenharmony_ci    int Init();
362498b56bSopenharmony_ci    int Recv(void *buffer, unsigned int bufferLen, int flags = MSG_PEEK);
372498b56bSopenharmony_ci    int RecvMsg(struct msghdr *hdr, int flags = 0);
382498b56bSopenharmony_ci    int Listen(unsigned int backlog);
392498b56bSopenharmony_ci    int Poll(short inEvent, short& outEvent, const std::chrono::milliseconds& timeout);
402498b56bSopenharmony_ci    int Accept();
412498b56bSopenharmony_ciprivate:
422498b56bSopenharmony_ci    int socketHandler;
432498b56bSopenharmony_ci    uint32_t socketType;
442498b56bSopenharmony_ci    sockaddr_un serverAddr;
452498b56bSopenharmony_ci    std::string socketName;
462498b56bSopenharmony_ci};
472498b56bSopenharmony_ci} // namespace HiviewDFX
482498b56bSopenharmony_ci} // namespace OHOS
492498b56bSopenharmony_ci#endif /* SOCKET_SERVER_H */
50