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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/mdns_client_impl.cc
diff --git a/net/dns/mdns_client_impl.cc b/net/dns/mdns_client_impl.cc
index 1745385784a8ec4ba1f6e1b420fa877f7b190d7f..941e9eec58ce4d9c959d30103ccd25dd93446b12 100644
--- a/net/dns/mdns_client_impl.cc
+++ b/net/dns/mdns_client_impl.cc
@@ -4,6 +4,8 @@
#include "net/dns/mdns_client_impl.h"
+#include <queue>
+
#include "base/bind.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/stl_util.h"
@@ -54,7 +56,8 @@ MDnsConnection::SocketHandler::SocketHandler(
MDnsConnection* connection)
: socket_(socket.Pass()),
connection_(connection),
- response_(dns_protocol::kMaxMulticastSize) {
+ response_(dns_protocol::kMaxMulticastSize),
+ send_in_progress_(false) {
}
MDnsConnection::SocketHandler::~SocketHandler() {
@@ -98,14 +101,30 @@ void MDnsConnection::SocketHandler::OnDatagramReceived(int rv) {
connection_->OnError(this, rv);
}
-int MDnsConnection::SocketHandler::Send(IOBuffer* buffer, unsigned size) {
- return socket_->SendTo(buffer, size, multicast_addr_,
- base::Bind(&MDnsConnection::SocketHandler::SendDone,
- base::Unretained(this) ));
+int MDnsConnection::SocketHandler::Send(
+ const scoped_refptr<IOBufferWithSize>& buffer) {
+ if (send_in_progress_) {
+ send_queue_.push(buffer);
+ return ERR_IO_PENDING;
+ }
+ int rv = socket_->SendTo(buffer.get(),
+ buffer->size(),
+ multicast_addr_,
+ base::Bind(&MDnsConnection::SocketHandler::SendDone,
+ base::Unretained(this)));
+ if (rv != ERR_IO_PENDING)
+ return rv;
+ send_in_progress_ = true;
+ return ERR_IO_PENDING;
}
void MDnsConnection::SocketHandler::SendDone(int rv) {
- // TODO(noamsml): Retry logic.
+ 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.
+ while (!send_in_progress_ && !send_queue_.empty()) {
+ scoped_refptr<IOBufferWithSize> buffer = send_queue_.front();
+ send_queue_.pop();
+ Send(buffer);
+ }
}
MDnsConnection::MDnsConnection(MDnsConnection::Delegate* delegate) :
@@ -141,10 +160,10 @@ bool MDnsConnection::Init(MDnsSocketFactory* socket_factory) {
return !socket_handlers_.empty();
}
-bool MDnsConnection::Send(IOBuffer* buffer, unsigned size) {
+bool MDnsConnection::Send(const scoped_refptr<IOBufferWithSize>& buffer) {
bool success = false;
for (size_t i = 0; i < socket_handlers_.size(); ++i) {
- int rv = socket_handlers_[i]->Send(buffer, size);
+ int rv = socket_handlers_[i]->Send(buffer);
if (rv >= OK || rv == ERR_IO_PENDING) {
success = true;
} else {
@@ -190,7 +209,7 @@ bool MDnsClientImpl::Core::SendQuery(uint16 rrtype, std::string name) {
DnsQuery query(0, name_dns, rrtype);
query.set_flags(0); // Remove the RD flag from the query. It is unneeded.
- return connection_->Send(query.io_buffer(), query.io_buffer()->size());
+ return connection_->Send(query.io_buffer());
}
void MDnsClientImpl::Core::HandlePacket(DnsResponse* response,
« 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