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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 | 76 |
77 net::IPEndPoint bound_ip_end_point; | 77 net::IPEndPoint bound_ip_end_point; |
78 NetAddressPtr bound_addr; | 78 NetAddressPtr bound_addr; |
79 net_result = socket_.GetLocalAddress(&bound_ip_end_point); | 79 net_result = socket_.GetLocalAddress(&bound_ip_end_point); |
80 if (net_result == net::OK) | 80 if (net_result == net::OK) |
81 bound_addr = NetAddress::From(bound_ip_end_point); | 81 bound_addr = NetAddress::From(bound_ip_end_point); |
82 | 82 |
83 bound_ = true; | 83 bound_ = true; |
84 callback.Run(MakeNetworkError(net::OK), bound_addr.Pass()); | 84 callback.Run(MakeNetworkError(net::OK), bound_addr.Pass()); |
| 85 |
| 86 if (remaining_recv_slots_ > 0) { |
| 87 DCHECK(!recvfrom_buffer_.get()); |
| 88 DoRecvFrom(); |
| 89 } |
85 } | 90 } |
86 | 91 |
87 void UDPSocketImpl::SetSendBufferSize( | 92 void UDPSocketImpl::SetSendBufferSize( |
88 uint32_t size, | 93 uint32_t size, |
89 const Callback<void(NetworkErrorPtr)>& callback) { | 94 const Callback<void(NetworkErrorPtr)>& callback) { |
90 if (!bound_) { | 95 if (!bound_) { |
91 callback.Run(MakeNetworkError(net::ERR_FAILED)); | 96 callback.Run(MakeNetworkError(net::ERR_FAILED)); |
92 return; | 97 return; |
93 } | 98 } |
94 | 99 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 pending_send_requests_.resize(max_pending_send_requests_); | 136 pending_send_requests_.resize(max_pending_send_requests_); |
132 for (auto& discarded_request : discarded_requests) { | 137 for (auto& discarded_request : discarded_requests) { |
133 discarded_request->callback.Run( | 138 discarded_request->callback.Run( |
134 MakeNetworkError(net::ERR_INSUFFICIENT_RESOURCES)); | 139 MakeNetworkError(net::ERR_INSUFFICIENT_RESOURCES)); |
135 delete discarded_request; | 140 delete discarded_request; |
136 } | 141 } |
137 } | 142 } |
138 } | 143 } |
139 | 144 |
140 void UDPSocketImpl::ReceiveMore(uint32_t datagram_number) { | 145 void UDPSocketImpl::ReceiveMore(uint32_t datagram_number) { |
141 if (!bound_ || datagram_number == 0) | 146 if (datagram_number == 0) |
142 return; | 147 return; |
143 if (std::numeric_limits<size_t>::max() - remaining_recv_slots_ < | 148 if (std::numeric_limits<size_t>::max() - remaining_recv_slots_ < |
144 datagram_number) { | 149 datagram_number) { |
145 return; | 150 return; |
146 } | 151 } |
147 | 152 |
148 remaining_recv_slots_ += datagram_number; | 153 remaining_recv_slots_ += datagram_number; |
149 | 154 |
150 if (!recvfrom_buffer_.get()) { | 155 if (bound_ && !recvfrom_buffer_.get()) { |
151 DCHECK_EQ(datagram_number, remaining_recv_slots_); | 156 DCHECK_EQ(datagram_number, remaining_recv_slots_); |
152 DoRecvFrom(); | 157 DoRecvFrom(); |
153 } | 158 } |
154 } | 159 } |
155 | 160 |
156 void UDPSocketImpl::SendTo(NetAddressPtr dest_addr, | 161 void UDPSocketImpl::SendTo(NetAddressPtr dest_addr, |
157 Array<uint8_t> data, | 162 Array<uint8_t> data, |
158 const Callback<void(NetworkErrorPtr)>& callback) { | 163 const Callback<void(NetworkErrorPtr)>& callback) { |
159 if (!bound_) { | 164 if (!bound_) { |
160 callback.Run(MakeNetworkError(net::ERR_FAILED)); | 165 callback.Run(MakeNetworkError(net::ERR_FAILED)); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 if (pending_send_requests_.empty()) | 271 if (pending_send_requests_.empty()) |
267 return; | 272 return; |
268 | 273 |
269 scoped_ptr<PendingSendRequest> request(pending_send_requests_.front()); | 274 scoped_ptr<PendingSendRequest> request(pending_send_requests_.front()); |
270 pending_send_requests_.pop_front(); | 275 pending_send_requests_.pop_front(); |
271 | 276 |
272 DoSendTo(request->addr.Pass(), request->data.Pass(), request->callback); | 277 DoSendTo(request->addr.Pass(), request->data.Pass(), request->callback); |
273 } | 278 } |
274 | 279 |
275 } // namespace mojo | 280 } // namespace mojo |
OLD | NEW |