• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
48 private:
49     std::shared_ptr<UnixSocketClient> unixSocketClient_;
50     int smbFd_;
51     int eventFd_;
52     int pid_;
53     int nmdFd_{0};
54     ClientConfig *config_ = nullptr;
55     Sampling *sampler_ = nullptr;
56     std::shared_ptr<StackWriter> stackWriter_;
57     std::shared_ptr<ShareMemoryBlock> shareMemoryBlockNmd_;
58     void (*disableHookCallback_)(){nullptr};
59 };
60 
61 #endif // HOOK_SOCKET_CLIENT