1/* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 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 HOOK_SOCKET_CLIENT 17#define HOOK_SOCKET_CLIENT 18 19#include "hook_common.h" 20#include "service_base.h" 21#include "stack_writer.h" 22 23class UnixSocketClient; 24class Sampling; 25 26class HookSocketClient : public ServiceBase { 27public: 28 HookSocketClient(int pid, ClientConfig *config, Sampling *sampler, void (*disableHookCallback)()); 29 ~HookSocketClient(); 30 bool Connect(const std::string addrname); 31 bool ProtocolProc(SocketContext &context, uint32_t pnum, const int8_t *buf, const uint32_t size) override; 32 int GetSmbFd() 33 { 34 return smbFd_; 35 } 36 int GetEventFd() 37 { 38 return eventFd_; 39 } 40 void Flush(); 41 bool SendStack(const void* data, size_t size); 42 bool SendStackWithPayload(const void* data, size_t size, const void* payload, 43 size_t payloadSize); 44 void DisableHook(); 45 bool PeerIsConnected(); 46 bool SendNmdInfo(); 47 bool SendEndMsg(); 48 int GetNmdType() 49 { 50 return nmdType_; 51 } 52 53private: 54 std::shared_ptr<UnixSocketClient> unixSocketClient_; 55 int smbFd_; 56 int eventFd_; 57 int pid_; 58 int nmdType_ = -1; 59 ClientConfig *config_ = nullptr; 60 Sampling *sampler_ = nullptr; 61 std::shared_ptr<StackWriter> stackWriter_; 62 void (*disableHookCallback_)(){nullptr}; 63}; 64 65#endif // HOOK_SOCKET_CLIENT