| OLD | NEW | 
|    1 // Copyright 2014 The Chromium Authors. All rights reserved. |    1 // Copyright 2014 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 "mojo/services/public/cpp/network/udp_socket_wrapper.h" |    5 #include "mojo/services/public/cpp/network/udp_socket_wrapper.h" | 
|    6  |    6  | 
|    7 #include <assert.h> |    7 #include <assert.h> | 
|    8  |    8  | 
|    9 #include "mojo/public/cpp/environment/logging.h" |    9 #include "mojo/public/cpp/environment/logging.h" | 
|   10  |   10  | 
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  117     request->dest_addr = dest_addr.Pass(); |  117     request->dest_addr = dest_addr.Pass(); | 
|  118     request->data = data.Pass(); |  118     request->data = data.Pass(); | 
|  119     request->callback = callback; |  119     request->callback = callback; | 
|  120     send_requests_.push(request); |  120     send_requests_.push(request); | 
|  121     return; |  121     return; | 
|  122   } |  122   } | 
|  123  |  123  | 
|  124   MOJO_DCHECK(send_requests_.empty()); |  124   MOJO_DCHECK(send_requests_.empty()); | 
|  125   current_pending_sends_++; |  125   current_pending_sends_++; | 
|  126   socket_->SendTo(dest_addr.Pass(), data.Pass(), |  126   socket_->SendTo(dest_addr.Pass(), data.Pass(), | 
|  127                   ErrorCallback(static_cast<typename ErrorCallback::Runnable*>( |  127                   ErrorCallback(static_cast<ErrorCallback::Runnable*>( | 
|  128                       new SendCallbackHandler(this, callback)))); |  128                       new SendCallbackHandler(this, callback)))); | 
|  129 } |  129 } | 
|  130  |  130  | 
|  131 void UDPSocketWrapper::OnReceived(NetworkErrorPtr result, |  131 void UDPSocketWrapper::OnReceived(NetworkErrorPtr result, | 
|  132                                   NetAddressPtr src_addr, |  132                                   NetAddressPtr src_addr, | 
|  133                                   Array<uint8_t> data) { |  133                                   Array<uint8_t> data) { | 
|  134   if (!receive_requests_.empty()) { |  134   if (!receive_requests_.empty()) { | 
|  135     // The cache should be empty if there are user requests waiting for data. |  135     // The cache should be empty if there are user requests waiting for data. | 
|  136     MOJO_DCHECK(receive_queue_.empty()); |  136     MOJO_DCHECK(receive_queue_.empty()); | 
|  137  |  137  | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  150   received_data->src_addr = src_addr.Pass(); |  150   received_data->src_addr = src_addr.Pass(); | 
|  151   received_data->data = data.Pass(); |  151   received_data->data = data.Pass(); | 
|  152   receive_queue_.push(received_data); |  152   receive_queue_.push(received_data); | 
|  153 } |  153 } | 
|  154  |  154  | 
|  155 void UDPSocketWrapper::Initialize(uint32_t requested_max_pending_sends) { |  155 void UDPSocketWrapper::Initialize(uint32_t requested_max_pending_sends) { | 
|  156   socket_.set_client(this); |  156   socket_.set_client(this); | 
|  157   socket_->NegotiateMaxPendingSendRequests( |  157   socket_->NegotiateMaxPendingSendRequests( | 
|  158       requested_max_pending_sends, |  158       requested_max_pending_sends, | 
|  159       Callback<void(uint32_t)>( |  159       Callback<void(uint32_t)>( | 
|  160           static_cast<typename Callback<void(uint32_t)>::Runnable*>( |  160           static_cast< Callback<void(uint32_t)>::Runnable*>( | 
|  161               new NegotiateCallbackHandler(this)))); |  161               new NegotiateCallbackHandler(this)))); | 
|  162   socket_->ReceiveMore(max_receive_queue_size_); |  162   socket_->ReceiveMore(max_receive_queue_size_); | 
|  163 } |  163 } | 
|  164  |  164  | 
|  165 void UDPSocketWrapper::OnNegotiateMaxPendingSendRequestsCompleted( |  165 void UDPSocketWrapper::OnNegotiateMaxPendingSendRequestsCompleted( | 
|  166     uint32_t actual_size) { |  166     uint32_t actual_size) { | 
|  167   MOJO_DCHECK(max_pending_sends_ == 1); |  167   MOJO_DCHECK(max_pending_sends_ == 1); | 
|  168  |  168  | 
|  169   if (actual_size == 0) { |  169   if (actual_size == 0) { | 
|  170     assert(false); |  170     assert(false); | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  189   if (current_pending_sends_ >= max_pending_sends_ || send_requests_.empty()) |  189   if (current_pending_sends_ >= max_pending_sends_ || send_requests_.empty()) | 
|  190     return false; |  190     return false; | 
|  191  |  191  | 
|  192   SendRequest* request = send_requests_.front(); |  192   SendRequest* request = send_requests_.front(); | 
|  193   send_requests_.pop(); |  193   send_requests_.pop(); | 
|  194  |  194  | 
|  195   current_pending_sends_++; |  195   current_pending_sends_++; | 
|  196  |  196  | 
|  197   socket_->SendTo( |  197   socket_->SendTo( | 
|  198       request->dest_addr.Pass(), request->data.Pass(), |  198       request->dest_addr.Pass(), request->data.Pass(), | 
|  199       ErrorCallback(static_cast<typename ErrorCallback::Runnable*>( |  199       ErrorCallback(static_cast<ErrorCallback::Runnable*>( | 
|  200           new SendCallbackHandler(this, request->callback)))); |  200           new SendCallbackHandler(this, request->callback)))); | 
|  201  |  201  | 
|  202   delete request; |  202   delete request; | 
|  203  |  203  | 
|  204   return true; |  204   return true; | 
|  205 } |  205 } | 
|  206  |  206  | 
|  207 }  // namespace mojo |  207 }  // namespace mojo | 
| OLD | NEW |