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 23 class UnixSocketClient; 24 class Sampling; 25 26 class HookSocketClient : public ServiceBase { 27 public: 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; GetSmbFd()32 int GetSmbFd() 33 { 34 return smbFd_; 35 } GetEventFd()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 SendSimplifiedNmdInfo(); 48 bool SendEndMsg(); GetNmdType()49 int GetNmdType() 50 { 51 return nmdType_; 52 } 53 54 private: 55 std::shared_ptr<UnixSocketClient> unixSocketClient_; 56 int smbFd_; 57 int eventFd_; 58 int pid_; 59 int nmdType_ = -1; 60 ClientConfig *config_ = nullptr; 61 Sampling *sampler_ = nullptr; 62 std::shared_ptr<StackWriter> stackWriter_; 63 void (*disableHookCallback_)(){nullptr}; 64 uint32_t largestSize_ = 0; 65 uint32_t secondLargestSize_ = 0; 66 uint32_t maxGrowthSize_ = 0; 67 uint32_t sampleInterval_ = 0; 68 }; 69 70 #endif // HOOK_SOCKET_CLIENT