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/network/udp_socket_impl.h" | 5 #include "mojo/services/network/udp_socket_impl.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 16 matching lines...) Expand all Loading... |
27 const size_t kMaxWriteSize = 128 * 1024; | 27 const size_t kMaxWriteSize = 128 * 1024; |
28 const size_t kMaxPendingSendRequestsUpperbound = 128; | 28 const size_t kMaxPendingSendRequestsUpperbound = 128; |
29 const size_t kDefaultMaxPendingSendRequests = 32; | 29 const size_t kDefaultMaxPendingSendRequests = 32; |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 UDPSocketImpl::PendingSendRequest::PendingSendRequest() {} | 33 UDPSocketImpl::PendingSendRequest::PendingSendRequest() {} |
34 | 34 |
35 UDPSocketImpl::PendingSendRequest::~PendingSendRequest() {} | 35 UDPSocketImpl::PendingSendRequest::~PendingSendRequest() {} |
36 | 36 |
37 UDPSocketImpl::UDPSocketImpl(InterfaceRequest<UDPSocket> request) | 37 UDPSocketImpl::UDPSocketImpl(InterfaceRequest<UDPSocket> request, |
| 38 scoped_ptr<mojo::AppRefCount> app_refcount) |
38 : binding_(this, request.Pass()), | 39 : binding_(this, request.Pass()), |
39 socket_(net::DatagramSocket::DEFAULT_BIND, | 40 socket_(net::DatagramSocket::DEFAULT_BIND, |
40 net::RandIntCallback(), | 41 net::RandIntCallback(), |
41 nullptr, | 42 nullptr, |
42 net::NetLog::Source()), | 43 net::NetLog::Source()), |
43 state_(NOT_BOUND_OR_CONNECTED), | 44 state_(NOT_BOUND_OR_CONNECTED), |
44 allow_address_reuse_(false), | 45 allow_address_reuse_(false), |
45 remaining_recv_slots_(0), | 46 remaining_recv_slots_(0), |
46 max_pending_send_requests_(kDefaultMaxPendingSendRequests) { | 47 max_pending_send_requests_(kDefaultMaxPendingSendRequests), |
| 48 app_refcount_(app_refcount.Pass()) { |
47 } | 49 } |
48 | 50 |
49 UDPSocketImpl::~UDPSocketImpl() { | 51 UDPSocketImpl::~UDPSocketImpl() { |
50 STLDeleteElements(&pending_send_requests_); | 52 STLDeleteElements(&pending_send_requests_); |
51 } | 53 } |
52 | 54 |
53 void UDPSocketImpl::AllowAddressReuse( | 55 void UDPSocketImpl::AllowAddressReuse( |
54 const Callback<void(NetworkErrorPtr)>& callback) { | 56 const Callback<void(NetworkErrorPtr)>& callback) { |
55 if (IsBoundOrConnected()) { | 57 if (IsBoundOrConnected()) { |
56 callback.Run(MakeNetworkError(net::ERR_FAILED)); | 58 callback.Run(MakeNetworkError(net::ERR_FAILED)); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 if (pending_send_requests_.empty()) | 369 if (pending_send_requests_.empty()) |
368 return; | 370 return; |
369 | 371 |
370 scoped_ptr<PendingSendRequest> request(pending_send_requests_.front()); | 372 scoped_ptr<PendingSendRequest> request(pending_send_requests_.front()); |
371 pending_send_requests_.pop_front(); | 373 pending_send_requests_.pop_front(); |
372 | 374 |
373 DoSendTo(request->addr.Pass(), request->data.Pass(), request->callback); | 375 DoSendTo(request->addr.Pass(), request->data.Pass(), request->callback); |
374 } | 376 } |
375 | 377 |
376 } // namespace mojo | 378 } // namespace mojo |
OLD | NEW |