1 /* 2 * Copyright (c) 2024 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 RS_PROFILER_SOCKET_H 17 #define RS_PROFILER_SOCKET_H 18 19 #include <cstddef> 20 #include <cstdint> 21 22 namespace OHOS::Rosen { 23 24 enum class SocketState { 25 INITIAL, 26 CREATE, 27 ACCEPT, 28 SHUTDOWN 29 }; 30 31 class Socket final { 32 public: 33 Socket() = default; 34 Socket(const Socket& other) = delete; 35 Socket(Socket&& other) = delete; 36 Socket& operator=(const Socket& other) = delete; 37 Socket& operator=(Socket&& other) = delete; 38 ~Socket(); 39 40 SocketState GetState() const; 41 void SetState(SocketState state); 42 void Shutdown(); 43 void Open(uint16_t port); 44 void AcceptClient(); 45 46 void GetStatus(bool& readyToReceive, bool& readyToSend) const; 47 48 void SendWhenReady(const void* data, size_t size); 49 bool Receive(void* data, size_t& size); 50 bool ReceiveWhenReady(void* data, size_t size); 51 52 private: 53 int32_t socket_ = -1; 54 int32_t client_ = -1; 55 SocketState state_ = SocketState::INITIAL; 56 }; 57 58 } // namespace OHOS::Rosen 59 60 #endif // RS_PROFILER_SOCKET_H