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

Unified Diff: mojo/services/network/udp_socket_impl.cc

Issue 880613005: De-Clientize UDPSocket service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rollin
Patch Set: Created 5 years, 11 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
Index: mojo/services/network/udp_socket_impl.cc
diff --git a/mojo/services/network/udp_socket_impl.cc b/mojo/services/network/udp_socket_impl.cc
index 524136a32744b49fd542a1c1a468485cc605f2bf..d46d3da533e9bd8671f6c9979b47970a5d5b752d 100644
--- a/mojo/services/network/udp_socket_impl.cc
+++ b/mojo/services/network/udp_socket_impl.cc
@@ -34,8 +34,9 @@ UDPSocketImpl::PendingSendRequest::PendingSendRequest() {}
UDPSocketImpl::PendingSendRequest::~PendingSendRequest() {}
-UDPSocketImpl::UDPSocketImpl()
- : socket_(net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(),
+UDPSocketImpl::UDPSocketImpl(InterfaceRequest<UDPSocket> request)
+ : binding_(this, request.Pass()),
+ socket_(net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(),
nullptr, net::NetLog::Source()),
state_(NOT_BOUND_OR_CONNECTED),
allow_address_reuse_(false),
@@ -215,6 +216,15 @@ void UDPSocketImpl::NegotiateMaxPendingSendRequests(
}
}
+void UDPSocketImpl::SetReceiver(UDPSocketReceiverPtr receiver) {
+ receiver_ = receiver.Pass();
+
+ // If there is a pending RecvFrom completion, we can continue it now.
+ if (recvfrom_buffer_.get()) {
+ OnRecvFromCompleted(recvfrom_result_);
+ }
+}
+
void UDPSocketImpl::ReceiveMore(uint32_t datagram_number) {
if (datagram_number == 0)
return;
@@ -323,6 +333,13 @@ void UDPSocketImpl::DoSendTo(NetAddressPtr addr,
void UDPSocketImpl::OnRecvFromCompleted(int net_result) {
DCHECK(recvfrom_buffer_.get());
+ // If no receiver is set yet, leave this RecvFrom operation in a pending
+ // state, preventing additional RecvFroms as well.
yzshen1 2015/01/28 19:31:06 This is a pretty clever way. :)
+ if (!receiver_) {
+ recvfrom_result_ = net_result;
+ return;
+ }
+
NetAddressPtr net_address;
Array<uint8_t> array;
if (net_result >= 0) {
@@ -337,9 +354,8 @@ void UDPSocketImpl::OnRecvFromCompleted(int net_result) {
}
recvfrom_buffer_ = nullptr;
- client()->OnReceived(MakeNetworkError(net_result), net_address.Pass(),
- array.Pass());
-
+ receiver_->OnReceived(MakeNetworkError(net_result), net_address.Pass(),
+ array.Pass());
DCHECK_GT(remaining_recv_slots_, 0u);
remaining_recv_slots_--;
if (remaining_recv_slots_ > 0)

Powered by Google App Engine
This is Rietveld 408576698