Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: net/dns/mdns_client_impl.cc

Issue 2684113002: [ON HOLD] Deallocate read buffer in MDnsClientImpl::SocketHandler if done reading (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/dns/mdns_client_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/mdns_client_impl.h" 5 #include "net/dns/mdns_client_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <queue> 8 #include <queue>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (socket) 54 if (socket)
55 sockets->push_back(std::move(socket)); 55 sockets->push_back(std::move(socket));
56 } 56 }
57 } 57 }
58 58
59 MDnsConnection::SocketHandler::SocketHandler( 59 MDnsConnection::SocketHandler::SocketHandler(
60 std::unique_ptr<DatagramServerSocket> socket, 60 std::unique_ptr<DatagramServerSocket> socket,
61 MDnsConnection* connection) 61 MDnsConnection* connection)
62 : socket_(std::move(socket)), 62 : socket_(std::move(socket)),
63 connection_(connection), 63 connection_(connection),
64 response_(dns_protocol::kMaxMulticastSize), 64 response_(new DnsResponse(dns_protocol::kMaxMulticastSize)),
65 send_in_progress_(false) {} 65 send_in_progress_(false) {}
66 66
67 MDnsConnection::SocketHandler::~SocketHandler() { 67 MDnsConnection::SocketHandler::~SocketHandler() {
68 } 68 }
69 69
70 int MDnsConnection::SocketHandler::Start() { 70 int MDnsConnection::SocketHandler::Start() {
71 IPEndPoint end_point; 71 IPEndPoint end_point;
72 int rv = socket_->GetLocalAddress(&end_point); 72 int rv = socket_->GetLocalAddress(&end_point);
73 if (rv != OK) 73 if (rv != OK)
74 return rv; 74 return rv;
75 DCHECK(end_point.GetFamily() == ADDRESS_FAMILY_IPV4 || 75 DCHECK(end_point.GetFamily() == ADDRESS_FAMILY_IPV4 ||
76 end_point.GetFamily() == ADDRESS_FAMILY_IPV6); 76 end_point.GetFamily() == ADDRESS_FAMILY_IPV6);
77 multicast_addr_ = GetMDnsIPEndPoint(end_point.GetFamily()); 77 multicast_addr_ = GetMDnsIPEndPoint(end_point.GetFamily());
78 return DoLoop(0); 78 return DoRead(0);
79 } 79 }
80 80
81 int MDnsConnection::SocketHandler::DoLoop(int rv) { 81 int MDnsConnection::SocketHandler::DoRead(int rv) {
82 DCHECK(response_);
82 do { 83 do {
83 if (rv > 0) 84 if (rv > 0)
84 connection_->OnDatagramReceived(&response_, recv_addr_, rv); 85 connection_->OnDatagramReceived(response_.get(), recv_addr_, rv);
85 86
86 rv = socket_->RecvFrom( 87 rv = socket_->RecvFrom(
87 response_.io_buffer(), response_.io_buffer()->size(), &recv_addr_, 88 response_->io_buffer(), response_->io_buffer()->size(), &recv_addr_,
88 base::Bind(&MDnsConnection::SocketHandler::OnDatagramReceived, 89 base::Bind(&MDnsConnection::SocketHandler::OnDatagramReceived,
89 base::Unretained(this))); 90 base::Unretained(this)));
90 } while (rv > 0); 91 } while (rv > 0);
91 92
92 if (rv != ERR_IO_PENDING) 93 if (rv == ERR_IO_PENDING)
93 return rv; 94 return OK;
94 95 response_.reset();
95 return OK; 96 return rv;
96 } 97 }
97 98
98 void MDnsConnection::SocketHandler::OnDatagramReceived(int rv) { 99 void MDnsConnection::SocketHandler::OnDatagramReceived(int rv) {
99 if (rv >= OK) 100 if (rv >= OK)
100 rv = DoLoop(rv); 101 rv = DoRead(rv);
101 102
102 if (rv != OK) 103 if (rv != OK) {
104 response_.reset();
103 connection_->PostOnError(this, rv); 105 connection_->PostOnError(this, rv);
106 }
104 } 107 }
105 108
106 void MDnsConnection::SocketHandler::Send(const scoped_refptr<IOBuffer>& buffer, 109 void MDnsConnection::SocketHandler::Send(const scoped_refptr<IOBuffer>& buffer,
107 unsigned size) { 110 unsigned size) {
108 if (send_in_progress_) { 111 if (send_in_progress_) {
109 send_queue_.push(std::make_pair(buffer, size)); 112 send_queue_.push(std::make_pair(buffer, size));
110 return; 113 return;
111 } 114 }
112 int rv = socket_->SendTo(buffer.get(), 115 int rv = socket_->SendTo(buffer.get(),
113 size, 116 size,
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 744
742 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) { 745 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) {
743 TriggerCallback(RESULT_NSEC, NULL); 746 TriggerCallback(RESULT_NSEC, NULL);
744 } 747 }
745 748
746 void MDnsTransactionImpl::OnCachePurged() { 749 void MDnsTransactionImpl::OnCachePurged() {
747 // TODO(noamsml): Cache purge situations not yet implemented 750 // TODO(noamsml): Cache purge situations not yet implemented
748 } 751 }
749 752
750 } // namespace net 753 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/mdns_client_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698