Chromium Code Reviews| 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, |