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 "net/udp/udp_socket_libevent.h" | 5 #include "net/udp/udp_socket_libevent.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <netdb.h> | 9 #include <netdb.h> |
10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 socket_options_ |= SOCKET_OPTION_REUSE_ADDRESS; | 285 socket_options_ |= SOCKET_OPTION_REUSE_ADDRESS; |
286 } | 286 } |
287 | 287 |
288 void UDPSocketLibevent::AllowBroadcast() { | 288 void UDPSocketLibevent::AllowBroadcast() { |
289 DCHECK(CalledOnValidThread()); | 289 DCHECK(CalledOnValidThread()); |
290 DCHECK(!is_connected()); | 290 DCHECK(!is_connected()); |
291 | 291 |
292 socket_options_ |= SOCKET_OPTION_BROADCAST; | 292 socket_options_ |= SOCKET_OPTION_BROADCAST; |
293 } | 293 } |
294 | 294 |
| 295 void UDPSocketLibevent::ReadWatcher::OnFileCanReadWithoutBlocking(int) { |
| 296 if (!socket_->read_callback_.is_null()) |
| 297 socket_->DidCompleteRead(); |
| 298 } |
| 299 |
| 300 void UDPSocketLibevent::WriteWatcher::OnFileCanWriteWithoutBlocking(int) { |
| 301 if (!socket_->write_callback_.is_null()) |
| 302 socket_->DidCompleteWrite(); |
| 303 } |
| 304 |
295 void UDPSocketLibevent::DoReadCallback(int rv) { | 305 void UDPSocketLibevent::DoReadCallback(int rv) { |
296 DCHECK_NE(rv, ERR_IO_PENDING); | 306 DCHECK_NE(rv, ERR_IO_PENDING); |
297 DCHECK(!read_callback_.is_null()); | 307 DCHECK(!read_callback_.is_null()); |
298 | 308 |
299 // since Run may result in Read being called, clear read_callback_ up front. | 309 // since Run may result in Read being called, clear read_callback_ up front. |
300 CompletionCallback c = read_callback_; | 310 CompletionCallback c = read_callback_; |
301 read_callback_.Reset(); | 311 read_callback_.Reset(); |
302 c.Run(rv); | 312 c.Run(rv); |
303 } | 313 } |
304 | 314 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 497 |
488 for (int i = 0; i < kBindRetries; ++i) { | 498 for (int i = 0; i < kBindRetries; ++i) { |
489 int rv = DoBind(IPEndPoint(ip, rand_int_cb_.Run(kPortStart, kPortEnd))); | 499 int rv = DoBind(IPEndPoint(ip, rand_int_cb_.Run(kPortStart, kPortEnd))); |
490 if (rv == OK || rv != ERR_ADDRESS_IN_USE) | 500 if (rv == OK || rv != ERR_ADDRESS_IN_USE) |
491 return rv; | 501 return rv; |
492 } | 502 } |
493 return DoBind(IPEndPoint(ip, 0)); | 503 return DoBind(IPEndPoint(ip, 0)); |
494 } | 504 } |
495 | 505 |
496 } // namespace net | 506 } // namespace net |
OLD | NEW |