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_TCP_CLIENT_H 17 #define OHOS_SHARING_TCP_CLIENT_H 18 19 #include <shared_mutex> 20 #include "base_client.h" 21 22 namespace OHOS { 23 namespace Sharing { 24 class TcpSocket; 25 26 class TcpClientEventListener : public BaseClientEventListener {}; 27 28 class TcpClientEventHandler : public BaseClientEventHandler {}; 29 30 class TcpClient final : public BaseClient { 31 public: 32 TcpClient(); 33 ~TcpClient() 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 &peerIp, uint16_t peerPort, const std::string &localIp, uint16_t localPort) override; 41 42 SocketInfo::Ptr GetSocketInfo() override; 43 44 void OnClientReadable(int32_t fd) override; 45 46 private: 47 std::shared_mutex mutex_; 48 std::shared_ptr<TcpSocket> socket_ = nullptr; 49 }; 50 } // namespace Sharing 51 } // namespace OHOS 52 #endif