OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/socket/udp_socket.h" | 5 #include "chrome/browser/extensions/api/socket/udp_socket.h" |
6 | 6 |
7 #include "chrome/browser/extensions/api/api_resource.h" | 7 #include "chrome/browser/extensions/api/api_resource.h" |
8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" | 8 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" |
9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 io_buffer.get(), | 178 io_buffer.get(), |
179 byte_count, | 179 byte_count, |
180 ip_end_point, | 180 ip_end_point, |
181 base::Bind(&UDPSocket::OnSendToComplete, base::Unretained(this))); | 181 base::Bind(&UDPSocket::OnSendToComplete, base::Unretained(this))); |
182 } while (false); | 182 } while (false); |
183 | 183 |
184 if (result != net::ERR_IO_PENDING) | 184 if (result != net::ERR_IO_PENDING) |
185 OnSendToComplete(result); | 185 OnSendToComplete(result); |
186 } | 186 } |
187 | 187 |
| 188 bool UDPSocket::IsTCPSocket() { |
| 189 return false; |
| 190 } |
| 191 |
| 192 bool UDPSocket::GetPeerAddress(net::IPEndPoint* address) { |
| 193 return !socket_.GetPeerAddress(address); |
| 194 } |
| 195 |
| 196 bool UDPSocket::GetLocalAddress(net::IPEndPoint* address) { |
| 197 return !socket_.GetLocalAddress(address); |
| 198 } |
| 199 |
188 void UDPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, | 200 void UDPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, |
189 int result) { | 201 int result) { |
190 DCHECK(!read_callback_.is_null()); | 202 DCHECK(!read_callback_.is_null()); |
191 read_callback_.Run(result, io_buffer); | 203 read_callback_.Run(result, io_buffer); |
192 read_callback_.Reset(); | 204 read_callback_.Reset(); |
193 } | 205 } |
194 | 206 |
195 void UDPSocket::OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, | 207 void UDPSocket::OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, |
196 scoped_refptr<IPEndPoint> address, | 208 scoped_refptr<IPEndPoint> address, |
197 int result) { | 209 int result) { |
198 DCHECK(!recv_from_callback_.is_null()); | 210 DCHECK(!recv_from_callback_.is_null()); |
199 std::string ip; | 211 std::string ip; |
200 int port = 0; | 212 int port = 0; |
201 if (result > 0 && address.get()) { | 213 if (result > 0 && address.get()) { |
202 IPEndPointToStringAndPort(address->data, &ip, &port); | 214 IPEndPointToStringAndPort(address->data, &ip, &port); |
203 } | 215 } |
204 recv_from_callback_.Run(result, io_buffer, ip, port); | 216 recv_from_callback_.Run(result, io_buffer, ip, port); |
205 recv_from_callback_.Reset(); | 217 recv_from_callback_.Reset(); |
206 } | 218 } |
207 | 219 |
208 void UDPSocket::OnSendToComplete(int result) { | 220 void UDPSocket::OnSendToComplete(int result) { |
209 DCHECK(!send_to_callback_.is_null()); | 221 DCHECK(!send_to_callback_.is_null()); |
210 send_to_callback_.Run(result); | 222 send_to_callback_.Run(result); |
211 send_to_callback_.Reset(); | 223 send_to_callback_.Reset(); |
212 } | 224 } |
213 | 225 |
214 } // namespace extensions | 226 } // namespace extensions |
OLD | NEW |