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 #include <unistd.h>
16
17 #include "dns_proxy_request_socket.h"
18 #include "netnative_log_wrapper.h"
19
20 namespace OHOS::nmd {
DnsProxyRequestSocket(int32_t sock,std::unique_ptr<AlignedSockAddr> && clientSock,std::unique_ptr<RecvBuff> && recvBuff)21 DnsProxyRequestSocket::DnsProxyRequestSocket(int32_t sock, std::unique_ptr<AlignedSockAddr> &&clientSock,
22 std::unique_ptr<RecvBuff> &&recvBuff)
23 {
24 NETNATIVE_LOG_D("dns_proxy_listen DnsProxyRequestSocket");
25 this->sock = sock;
26 event.data.fd = sock;
27 event.events = EPOLLIN;
28 this->clientSock = std::move(clientSock);
29 this->recvBuff = std::move(recvBuff);
30 endTime = std::chrono::system_clock::now() + std::chrono::milliseconds(EPOLL_TIMEOUT);
31 }
32
~DnsProxyRequestSocket()33 DnsProxyRequestSocket::~DnsProxyRequestSocket()
34 {
35 NETNATIVE_LOG_D("dns_proxy_listen ~DnsProxyRequestSocket sock: %{public}d", sock);
36 if (sock > 0) {
37 close(sock);
38 }
39 }
40
GetSock() const41 int32_t DnsProxyRequestSocket::GetSock() const
42 {
43 return sock;
44 }
45
GetIdx() const46 size_t DnsProxyRequestSocket::GetIdx() const
47 {
48 return dnsServerIdx;
49 }
50
ResetIdx()51 void DnsProxyRequestSocket::ResetIdx()
52 {
53 dnsServerIdx = 0;
54 }
55
IncreaseIdx()56 void DnsProxyRequestSocket::IncreaseIdx()
57 {
58 dnsServerIdx++;
59 }
60
GetEventPtr()61 epoll_event *DnsProxyRequestSocket::GetEventPtr()
62 {
63 return &event;
64 }
65
GetAddr()66 AlignedSockAddr &DnsProxyRequestSocket::GetAddr()
67 {
68 return this->addrParse;
69 }
GetClientSock()70 AlignedSockAddr &DnsProxyRequestSocket::GetClientSock()
71 {
72 return *clientSock;
73 }
GetRecvBuff()74 RecvBuff &DnsProxyRequestSocket::GetRecvBuff()
75 {
76 return *recvBuff;
77 }
78
GetLruIterator() const79 std::list<std::map<int32_t, DnsProxyRequestSocket>::iterator>::iterator DnsProxyRequestSocket::GetLruIterator() const
80 {
81 return this->lruIterator;
82 }
83
SetLruIterator(std::list<std::map<int32_t,DnsProxyRequestSocket>::iterator>::iterator iterator)84 void DnsProxyRequestSocket::SetLruIterator(
85 std::list<std::map<int32_t, DnsProxyRequestSocket>::iterator>::iterator iterator)
86 {
87 this->lruIterator = iterator;
88 }
89 } // namespace OHOS::nmd
90