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 16 #ifndef RPC_HTTPSOCKET_H 17 #define RPC_HTTPSOCKET_H 18 19 #include <string> 20 namespace SysTuning { 21 namespace TraceStreamer { 22 class HttpSocket { 23 public: HttpSocket()24 HttpSocket() {} HttpSocket(int sockId,int domain)25 HttpSocket(int sockId, int domain) : sockId_(sockId), domain_(domain) {} 26 ~HttpSocket(); 27 28 bool CreateSocket(int domain); 29 bool Bind(int port); 30 bool Listen(int maxConn); 31 bool Accept(HttpSocket& client); 32 bool Recv(void* data, size_t& len); 33 bool Send(const void* data, size_t len); 34 void Close(); GetFd()35 int GetFd() 36 { 37 return sockId_; 38 } 39 40 private: 41 int sockId_ = -1; 42 int domain_ = 0; 43 #ifndef _WIN32 44 using SOCKET = int; 45 const int SOCKET_ERROR = -1; 46 const SOCKET INVALID_SOCKET = -1; 47 #endif 48 }; 49 } // namespace TraceStreamer 50 } // namespace SysTuning 51 #endif // RPC_HTTPSOCKET_H 52