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

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

Issue 581813004: Enqueue mDns requests if send on socket in progress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fri Sep 19 01:27:40 PDT 2014 Created 6 years, 3 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') | net/dns/mdns_client_unittest.cc » ('j') | 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 <queue>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/stl_util.h" 11 #include "base/stl_util.h"
10 #include "base/time/default_clock.h" 12 #include "base/time/default_clock.h"
11 #include "base/time/time.h" 13 #include "base/time/time.h"
12 #include "net/base/dns_util.h" 14 #include "net/base/dns_util.h"
13 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
14 #include "net/base/net_log.h" 16 #include "net/base/net_log.h"
15 #include "net/base/rand_callback.h" 17 #include "net/base/rand_callback.h"
16 #include "net/dns/dns_protocol.h" 18 #include "net/dns/dns_protocol.h"
(...skipping 30 matching lines...) Expand all
47 if (socket) 49 if (socket)
48 sockets->push_back(socket.release()); 50 sockets->push_back(socket.release());
49 } 51 }
50 } 52 }
51 53
52 MDnsConnection::SocketHandler::SocketHandler( 54 MDnsConnection::SocketHandler::SocketHandler(
53 scoped_ptr<DatagramServerSocket> socket, 55 scoped_ptr<DatagramServerSocket> socket,
54 MDnsConnection* connection) 56 MDnsConnection* connection)
55 : socket_(socket.Pass()), 57 : socket_(socket.Pass()),
56 connection_(connection), 58 connection_(connection),
57 response_(dns_protocol::kMaxMulticastSize) { 59 response_(dns_protocol::kMaxMulticastSize),
60 send_in_progress_(false) {
58 } 61 }
59 62
60 MDnsConnection::SocketHandler::~SocketHandler() { 63 MDnsConnection::SocketHandler::~SocketHandler() {
61 } 64 }
62 65
63 int MDnsConnection::SocketHandler::Start() { 66 int MDnsConnection::SocketHandler::Start() {
64 IPEndPoint end_point; 67 IPEndPoint end_point;
65 int rv = socket_->GetLocalAddress(&end_point); 68 int rv = socket_->GetLocalAddress(&end_point);
66 if (rv != OK) 69 if (rv != OK)
67 return rv; 70 return rv;
(...skipping 23 matching lines...) Expand all
91 } 94 }
92 95
93 void MDnsConnection::SocketHandler::OnDatagramReceived(int rv) { 96 void MDnsConnection::SocketHandler::OnDatagramReceived(int rv) {
94 if (rv >= OK) 97 if (rv >= OK)
95 rv = DoLoop(rv); 98 rv = DoLoop(rv);
96 99
97 if (rv != OK) 100 if (rv != OK)
98 connection_->OnError(this, rv); 101 connection_->OnError(this, rv);
99 } 102 }
100 103
101 int MDnsConnection::SocketHandler::Send(IOBuffer* buffer, unsigned size) { 104 int MDnsConnection::SocketHandler::Send(
102 return socket_->SendTo(buffer, size, multicast_addr_, 105 const scoped_refptr<IOBufferWithSize>& buffer) {
103 base::Bind(&MDnsConnection::SocketHandler::SendDone, 106 if (send_in_progress_) {
104 base::Unretained(this) )); 107 send_queue_.push(buffer);
108 return ERR_IO_PENDING;
109 }
110 int rv = socket_->SendTo(buffer.get(),
111 buffer->size(),
112 multicast_addr_,
113 base::Bind(&MDnsConnection::SocketHandler::SendDone,
114 base::Unretained(this)));
115 if (rv != ERR_IO_PENDING)
116 return rv;
117 send_in_progress_ = true;
118 return ERR_IO_PENDING;
105 } 119 }
106 120
107 void MDnsConnection::SocketHandler::SendDone(int rv) { 121 void MDnsConnection::SocketHandler::SendDone(int rv) {
108 // TODO(noamsml): Retry logic. 122 send_in_progress_ = false;
Sergey Ulanov 2014/09/19 20:40:19 |rv| is ignored here. I'm not sure how important i
Vitaly Buka (NO REVIEWS) 2014/09/19 21:01:45 Done.
123 while (!send_in_progress_ && !send_queue_.empty()) {
124 scoped_refptr<IOBufferWithSize> buffer = send_queue_.front();
125 send_queue_.pop();
126 Send(buffer);
127 }
109 } 128 }
110 129
111 MDnsConnection::MDnsConnection(MDnsConnection::Delegate* delegate) : 130 MDnsConnection::MDnsConnection(MDnsConnection::Delegate* delegate) :
112 delegate_(delegate) { 131 delegate_(delegate) {
113 } 132 }
114 133
115 MDnsConnection::~MDnsConnection() { 134 MDnsConnection::~MDnsConnection() {
116 } 135 }
117 136
118 bool MDnsConnection::Init(MDnsSocketFactory* socket_factory) { 137 bool MDnsConnection::Init(MDnsSocketFactory* socket_factory) {
(...skipping 15 matching lines...) Expand all
134 socket_handlers_.erase(socket_handlers_.begin() + i); 153 socket_handlers_.erase(socket_handlers_.begin() + i);
135 VLOG(1) << "Start failed, socket=" << i << ", error=" << rv; 154 VLOG(1) << "Start failed, socket=" << i << ", error=" << rv;
136 } else { 155 } else {
137 ++i; 156 ++i;
138 } 157 }
139 } 158 }
140 VLOG(1) << "Sockets ready:" << socket_handlers_.size(); 159 VLOG(1) << "Sockets ready:" << socket_handlers_.size();
141 return !socket_handlers_.empty(); 160 return !socket_handlers_.empty();
142 } 161 }
143 162
144 bool MDnsConnection::Send(IOBuffer* buffer, unsigned size) { 163 bool MDnsConnection::Send(const scoped_refptr<IOBufferWithSize>& buffer) {
145 bool success = false; 164 bool success = false;
146 for (size_t i = 0; i < socket_handlers_.size(); ++i) { 165 for (size_t i = 0; i < socket_handlers_.size(); ++i) {
147 int rv = socket_handlers_[i]->Send(buffer, size); 166 int rv = socket_handlers_[i]->Send(buffer);
148 if (rv >= OK || rv == ERR_IO_PENDING) { 167 if (rv >= OK || rv == ERR_IO_PENDING) {
149 success = true; 168 success = true;
150 } else { 169 } else {
151 VLOG(1) << "Send failed, socket=" << i << ", error=" << rv; 170 VLOG(1) << "Send failed, socket=" << i << ", error=" << rv;
152 } 171 }
153 } 172 }
154 return success; 173 return success;
155 } 174 }
156 175
157 void MDnsConnection::OnError(SocketHandler* loop, 176 void MDnsConnection::OnError(SocketHandler* loop,
(...skipping 25 matching lines...) Expand all
183 } 202 }
184 203
185 bool MDnsClientImpl::Core::SendQuery(uint16 rrtype, std::string name) { 204 bool MDnsClientImpl::Core::SendQuery(uint16 rrtype, std::string name) {
186 std::string name_dns; 205 std::string name_dns;
187 if (!DNSDomainFromDot(name, &name_dns)) 206 if (!DNSDomainFromDot(name, &name_dns))
188 return false; 207 return false;
189 208
190 DnsQuery query(0, name_dns, rrtype); 209 DnsQuery query(0, name_dns, rrtype);
191 query.set_flags(0); // Remove the RD flag from the query. It is unneeded. 210 query.set_flags(0); // Remove the RD flag from the query. It is unneeded.
192 211
193 return connection_->Send(query.io_buffer(), query.io_buffer()->size()); 212 return connection_->Send(query.io_buffer());
194 } 213 }
195 214
196 void MDnsClientImpl::Core::HandlePacket(DnsResponse* response, 215 void MDnsClientImpl::Core::HandlePacket(DnsResponse* response,
197 int bytes_read) { 216 int bytes_read) {
198 unsigned offset; 217 unsigned offset;
199 // Note: We store cache keys rather than record pointers to avoid 218 // Note: We store cache keys rather than record pointers to avoid
200 // erroneous behavior in case a packet contains multiple exclusive 219 // erroneous behavior in case a packet contains multiple exclusive
201 // records with the same type and name. 220 // records with the same type and name.
202 std::map<MDnsCache::Key, MDnsCache::UpdateType> update_keys; 221 std::map<MDnsCache::Key, MDnsCache::UpdateType> update_keys;
203 222
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 720
702 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) { 721 void MDnsTransactionImpl::OnNsecRecord(const std::string& name, unsigned type) {
703 TriggerCallback(RESULT_NSEC, NULL); 722 TriggerCallback(RESULT_NSEC, NULL);
704 } 723 }
705 724
706 void MDnsTransactionImpl::OnCachePurged() { 725 void MDnsTransactionImpl::OnCachePurged() {
707 // TODO(noamsml): Cache purge situations not yet implemented 726 // TODO(noamsml): Cache purge situations not yet implemented
708 } 727 }
709 728
710 } // namespace net 729 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/mdns_client_impl.h ('k') | net/dns/mdns_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698