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#include "socket_client.h" 17 18#include <cstdint> 19#include <iosfwd> 20#include <securec.h> 21#include <string> 22#include <sys/socket.h> 23#include <sys/un.h> 24#include <unistd.h> 25 26#include "hilog_common.h" 27#include "socket.h" 28 29namespace OHOS { 30namespace HiviewDFX { 31SocketClient::SocketClient(std::string serverPath, uint32_t socketType) : Socket(socketType) 32{ 33 serverAddr.sun_family = AF_UNIX; 34 std::string sockPath(SOCKET_FILE_DIR); 35 sockPath += serverPath; 36 if (strcpy_s(serverAddr.sun_path, sizeof(serverAddr.sun_path), sockPath.c_str()) != EOK) { 37 return; 38 } 39} 40 41int SocketClient::Connect() 42{ 43 return TEMP_FAILURE_RETRY(connect(socketHandler, reinterpret_cast<sockaddr*>(&serverAddr), sizeof(serverAddr))); 44} 45} // namespace HiviewDFX 46} // namespace OHOS 47