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) { | 188 bool UDPSocket::GetPeerAddress(net::IPEndPoint* address) { |
193 return !socket_.GetPeerAddress(address); | 189 return !socket_.GetPeerAddress(address); |
194 } | 190 } |
195 | 191 |
196 bool UDPSocket::GetLocalAddress(net::IPEndPoint* address) { | 192 bool UDPSocket::GetLocalAddress(net::IPEndPoint* address) { |
197 return !socket_.GetLocalAddress(address); | 193 return !socket_.GetLocalAddress(address); |
198 } | 194 } |
199 | 195 |
| 196 Socket::SocketType UDPSocket::socket_type() const { |
| 197 return Socket::TYPE_UDP; |
| 198 } |
| 199 |
200 void UDPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, | 200 void UDPSocket::OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, |
201 int result) { | 201 int result) { |
202 DCHECK(!read_callback_.is_null()); | 202 DCHECK(!read_callback_.is_null()); |
203 read_callback_.Run(result, io_buffer); | 203 read_callback_.Run(result, io_buffer); |
204 read_callback_.Reset(); | 204 read_callback_.Reset(); |
205 } | 205 } |
206 | 206 |
207 void UDPSocket::OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, | 207 void UDPSocket::OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, |
208 scoped_refptr<IPEndPoint> address, | 208 scoped_refptr<IPEndPoint> address, |
209 int result) { | 209 int result) { |
210 DCHECK(!recv_from_callback_.is_null()); | 210 DCHECK(!recv_from_callback_.is_null()); |
211 std::string ip; | 211 std::string ip; |
212 int port = 0; | 212 int port = 0; |
213 if (result > 0 && address.get()) { | 213 if (result > 0 && address.get()) { |
214 IPEndPointToStringAndPort(address->data, &ip, &port); | 214 IPEndPointToStringAndPort(address->data, &ip, &port); |
215 } | 215 } |
216 recv_from_callback_.Run(result, io_buffer, ip, port); | 216 recv_from_callback_.Run(result, io_buffer, ip, port); |
217 recv_from_callback_.Reset(); | 217 recv_from_callback_.Reset(); |
218 } | 218 } |
219 | 219 |
220 void UDPSocket::OnSendToComplete(int result) { | 220 void UDPSocket::OnSendToComplete(int result) { |
221 DCHECK(!send_to_callback_.is_null()); | 221 DCHECK(!send_to_callback_.is_null()); |
222 send_to_callback_.Run(result); | 222 send_to_callback_.Run(result); |
223 send_to_callback_.Reset(); | 223 send_to_callback_.Reset(); |
224 } | 224 } |
225 | 225 |
226 } // namespace extensions | 226 } // namespace extensions |
OLD | NEW |