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_EXTRA_OPTIONS_BASE_H
17 #define COMMUNICATIONNETSTACK_EXTRA_OPTIONS_BASE_H
18 
19 #include <cstdint>
20 
21 namespace OHOS::NetStack::Socket {
22 class ExtraOptionsBase {
23 public:
24     ExtraOptionsBase();
25 
26     ~ExtraOptionsBase() = default;
27 
28     void SetReceiveBufferSize(uint32_t receiveBufferSize);
29 
30     void SetSendBufferSize(uint32_t sendBufferSize);
31 
32     void SetReuseAddress(bool reuseAddress);
33 
34     void SetSocketTimeout(uint32_t socketTimeout);
35 
36     [[nodiscard]] uint32_t GetReceiveBufferSize() const;
37 
38     [[nodiscard]] uint32_t GetSendBufferSize() const;
39 
40     [[nodiscard]] bool IsReuseAddress() const;
41 
42     [[nodiscard]] uint32_t GetSocketTimeout() const;
43 
44     [[nodiscard]] bool AlreadySetRecvBufSize() const;
45 
46     void SetRecvBufSizeFlag(bool flag);
47 
48     [[nodiscard]] bool AlreadySetSendBufSize() const;
49 
50     void SetSendBufSizeFlag(bool flag);
51 
52     [[nodiscard]] bool AlreadySetTimeout() const;
53 
54     void SetTimeoutFlag(bool flag);
55 
56     [[nodiscard]] bool AlreadySetReuseAddr() const;
57 
58     void SetReuseaddrFlag(bool flag);
59 
60 private:
61     uint32_t receiveBufferSize_;
62 
63     uint32_t sendBufferSize_;
64 
65     bool reuseAddress_;
66 
67     uint32_t socketTimeout_;
68 
69     bool recvBufSizeFlag_ = false;
70 
71     bool sendBufSizeFlag_ = false;
72 
73     bool timeoutFlag_ = false;
74 
75     bool reuseAddrFlag_ = false;
76 };
77 } // namespace OHOS::NetStack::Socket
78 
79 #endif /* COMMUNICATIONNETSTACK_EXTRA_OPTIONS_BASE_H */
80