1 /* 2 * Copyright (c) 2021-2022 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 COMMUNICATIONNETSTACK_TCP_EXTRA_OPTIONS_H 17 #define COMMUNICATIONNETSTACK_TCP_EXTRA_OPTIONS_H 18 19 #include <cstdint> 20 21 #include "extra_options_base.h" 22 23 namespace OHOS::NetStack::Socket { 24 class TCPExtraOptions final : public ExtraOptionsBase { 25 private: 26 class SocketLinger { 27 public: 28 SocketLinger(); 29 30 ~SocketLinger() = default; 31 32 void SetOn(bool on); 33 34 void SetLinger(uint32_t linger); 35 36 [[nodiscard]] bool IsOn() const; 37 38 [[nodiscard]] uint32_t GetLinger() const; 39 40 private: 41 bool on_; 42 uint32_t linger_; 43 }; 44 45 public: 46 TCPExtraOptions(); 47 48 ~TCPExtraOptions() = default; 49 50 void SetKeepAlive(bool keepAlive); 51 52 void SetOOBInline(bool OOBInline); 53 54 void SetTCPNoDelay(bool TCPNoDelay); 55 56 [[nodiscard]] bool IsKeepAlive() const; 57 58 [[nodiscard]] bool IsOOBInline() const; 59 60 [[nodiscard]] bool IsTCPNoDelay() const; 61 62 [[nodiscard]] bool AlreadySetKeepAlive() const; 63 64 void SetKeepAliveFlag(bool flag); 65 66 [[nodiscard]] bool AlreadySetOobInline() const; 67 68 void SetOobInlineFlag(bool flag); 69 70 [[nodiscard]] bool AlreadySetTcpNoDelay() const; 71 72 void SetTcpNoDelayFlag(bool flag); 73 74 [[nodiscard]] bool AlreadySetLinger() const; 75 76 void SetLingerFlag(bool flag); 77 78 SocketLinger socketLinger; 79 80 private: 81 bool keepAlive_; 82 83 bool OOBInline_; 84 85 bool TCPNoDelay_; 86 87 bool keepAliveFlag_ = false; 88 89 bool oobInlineFlag_ = false; 90 91 bool tcpNoDelayFlag_ = false; 92 93 bool lingerFlag_ = false; 94 }; 95 } // namespace OHOS::NetStack::Socket 96 97 #endif /* COMMUNICATIONNETSTACK_TCP_EXTRA_OPTIONS_H */ 98