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 int WriteUvTcpFd(uv_tcp_t *tcp, uint8_t *buf, int size); 26 27 protected: RecvUDPEntry(const sockaddr * addrSrc,uv_udp_t * handle,const uv_buf_t * rcvbuf)28 virtual void RecvUDPEntry(const sockaddr *addrSrc, uv_udp_t *handle, const uv_buf_t *rcvbuf) 29 { 30 } 31 static void RecvUDP( 32 uv_udp_t *handle, ssize_t nread, const uv_buf_t *rcvbuf, const struct sockaddr *addr, unsigned flags); 33 static void SendUDPFinish(uv_udp_send_t *req, int status); 34 static void AllocStreamUDP(uv_handle_t *handle, size_t sizeWanted, uv_buf_t *buf); 35 36 void *clsMainBase; 37 bool serverOrDaemon; 38 std::mutex writeTCPMutex; 39 40 private: 41 void InitialChildClass(const bool serverOrDaemonIn, void *ptrMainBase); 42 }; 43 } // namespace Hdc 44 45 #endif 46