• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 #ifndef OHOS_SHARING_UDP_CLIENT_H
17 #define OHOS_SHARING_UDP_CLIENT_H
18 
19 #include <shared_mutex>
20 #include "base_client.h"
21 
22 namespace OHOS {
23 namespace Sharing {
24 class UdpSocket;
25 
26 class UdpClientEventListener : public BaseClientEventListener {};
27 
28 class UdpClientEventHandler : public BaseClientEventHandler {};
29 
30 class UdpClient final : public BaseClient {
31 public:
32     UdpClient();
33     ~UdpClient() override;
34 
35     bool Send(const std::string &msg) override;
36     bool Send(const char *buf, int32_t nSize) override;
37     bool Send(const DataBuffer::Ptr &buf, int32_t nSize) override;
38 
39     void Disconnect() override;
40     bool Connect(const std::string &peerHost, uint16_t peerPort, const std::string &localIp,
41                  uint16_t localPort) override;
42 
43     SocketInfo::Ptr GetSocketInfo() override;
44 
45     void OnClientReadable(int32_t fd) override;
46 
47 private:
48     std::shared_mutex mutex_;
49     std::shared_ptr<UdpSocket> socket_ = nullptr;
50 };
51 } // namespace Sharing
52 } // namespace OHOS
53 #endif