1 /* 2 * Copyright (C) 2021 Huawei Device 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 #ifndef HDC_TCP_H 16 #define HDC_TCP_H 17 #include "common.h" 18 19 namespace Hdc { 20 class HdcTCPBase { 21 public: 22 HdcTCPBase(const bool serverOrDaemonIn, void *ptrMainBase); 23 virtual ~HdcTCPBase(); 24 static void ReadStream(uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf); 25 bool WriteUvSslFd(uv_tcp_t *tcp, uint8_t *buf, int size, int &cnt); 26 int WriteUvTcpFd(uv_tcp_t *tcp, uint8_t *buf, int size); 27 28 protected: RecvUDPEntry(const sockaddr * addrSrc,uv_udp_t * handle,const uv_buf_t * rcvbuf)29 virtual void RecvUDPEntry(const sockaddr *addrSrc, uv_udp_t *handle, const uv_buf_t *rcvbuf) 30 { 31 } 32 static void RecvUDP( 33 uv_udp_t *handle, ssize_t nread, const uv_buf_t *rcvbuf, const struct sockaddr *addr, unsigned flags); 34 static void SendUDPFinish(uv_udp_send_t *req, int status); 35 static void AllocStreamUDP(uv_handle_t *handle, size_t sizeWanted, uv_buf_t *buf); 36 37 void *clsMainBase; 38 bool serverOrDaemon; 39 std::mutex writeTCPMutex; 40 41 private: 42 void InitialChildClass(const bool serverOrDaemonIn, void *ptrMainBase); 43 }; 44 } // namespace Hdc 45 46 #endif 47