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 #include "tcp_extra_options.h"
17 
18 namespace OHOS::NetStack::Socket {
SocketLinger()19 TCPExtraOptions::SocketLinger::SocketLinger() : on_(false), linger_(0) {}
20 
SetOn(bool on)21 void TCPExtraOptions::SocketLinger::SetOn(bool on)
22 {
23     on_ = on;
24 }
25 
SetLinger(uint32_t linger)26 void TCPExtraOptions::SocketLinger::SetLinger(uint32_t linger)
27 {
28     linger_ = linger;
29 }
30 
IsOn() const31 bool TCPExtraOptions::SocketLinger::IsOn() const
32 {
33     return on_;
34 }
35 
GetLinger() const36 uint32_t TCPExtraOptions::SocketLinger::GetLinger() const
37 {
38     return linger_;
39 }
40 
TCPExtraOptions()41 TCPExtraOptions::TCPExtraOptions() : keepAlive_(false), OOBInline_(false), TCPNoDelay_(false) {}
42 
SetKeepAlive(bool keepAlive)43 void TCPExtraOptions::SetKeepAlive(bool keepAlive)
44 {
45     keepAlive_ = keepAlive;
46 }
47 
SetOOBInline(bool OOBInline)48 void TCPExtraOptions::SetOOBInline(bool OOBInline)
49 {
50     OOBInline_ = OOBInline;
51 }
52 
SetTCPNoDelay(bool TCPNoDelay)53 void TCPExtraOptions::SetTCPNoDelay(bool TCPNoDelay)
54 {
55     TCPNoDelay_ = TCPNoDelay;
56 }
57 
IsKeepAlive() const58 bool TCPExtraOptions::IsKeepAlive() const
59 {
60     return keepAlive_;
61 }
62 
IsOOBInline() const63 bool TCPExtraOptions::IsOOBInline() const
64 {
65     return OOBInline_;
66 }
67 
IsTCPNoDelay() const68 bool TCPExtraOptions::IsTCPNoDelay() const
69 {
70     return TCPNoDelay_;
71 }
72 
AlreadySetKeepAlive() const73 bool TCPExtraOptions::AlreadySetKeepAlive() const
74 {
75     return keepAliveFlag_;
76 }
77 
SetKeepAliveFlag(bool flag)78 void TCPExtraOptions::SetKeepAliveFlag(bool flag)
79 {
80     keepAliveFlag_ = flag;
81 }
82 
AlreadySetOobInline() const83 bool TCPExtraOptions::AlreadySetOobInline() const
84 {
85     return oobInlineFlag_;
86 }
87 
SetOobInlineFlag(bool flag)88 void TCPExtraOptions::SetOobInlineFlag(bool flag)
89 {
90     oobInlineFlag_ = flag;
91 }
92 
AlreadySetTcpNoDelay() const93 bool TCPExtraOptions::AlreadySetTcpNoDelay() const
94 {
95     return tcpNoDelayFlag_;
96 }
97 
SetTcpNoDelayFlag(bool flag)98 void TCPExtraOptions::SetTcpNoDelayFlag(bool flag)
99 {
100     tcpNoDelayFlag_ = flag;
101 }
102 
AlreadySetLinger() const103 bool TCPExtraOptions::AlreadySetLinger() const
104 {
105     return lingerFlag_;
106 }
107 
SetLingerFlag(bool flag)108 void TCPExtraOptions::SetLingerFlag(bool flag)
109 {
110     lingerFlag_ = flag;
111 }
112 } // namespace OHOS::NetStack::Socket