| 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 "media/cast/net/udp_transport.h" | 5 #include "media/cast/net/udp_transport.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/bind.h" | 10 #include "base/bind.h" | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 62   DCHECK(!IsEmpty(local_end_point) || !IsEmpty(remote_end_point)); | 62   DCHECK(!IsEmpty(local_end_point) || !IsEmpty(remote_end_point)); | 
| 63 } | 63 } | 
| 64 | 64 | 
| 65 UdpTransport::~UdpTransport() {} | 65 UdpTransport::~UdpTransport() {} | 
| 66 | 66 | 
| 67 void UdpTransport::StartReceiving( | 67 void UdpTransport::StartReceiving( | 
| 68     const PacketReceiverCallback& packet_receiver) { | 68     const PacketReceiverCallback& packet_receiver) { | 
| 69   DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); | 69   DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); | 
| 70 | 70 | 
| 71   packet_receiver_ = packet_receiver; | 71   packet_receiver_ = packet_receiver; | 
| 72   udp_socket_->AllowAddressReuse(); |  | 
| 73   udp_socket_->SetMulticastLoopbackMode(true); | 72   udp_socket_->SetMulticastLoopbackMode(true); | 
| 74   if (!IsEmpty(local_addr_)) { | 73   if (!IsEmpty(local_addr_)) { | 
| 75     if (udp_socket_->Bind(local_addr_) < 0) { | 74     if (udp_socket_->Open(local_addr_.GetFamily()) < 0 || | 
|  | 75         udp_socket_->AllowAddressReuse() < 0 || | 
|  | 76         udp_socket_->Bind(local_addr_) < 0) { | 
|  | 77       udp_socket_->Close(); | 
| 76       status_callback_.Run(TRANSPORT_SOCKET_ERROR); | 78       status_callback_.Run(TRANSPORT_SOCKET_ERROR); | 
| 77       LOG(ERROR) << "Failed to bind local address."; | 79       LOG(ERROR) << "Failed to bind local address."; | 
| 78       return; | 80       return; | 
| 79     } | 81     } | 
| 80   } else if (!IsEmpty(remote_addr_)) { | 82   } else if (!IsEmpty(remote_addr_)) { | 
| 81     if (udp_socket_->Connect(remote_addr_) < 0) { | 83     if (udp_socket_->Open(remote_addr_.GetFamily()) < 0 || | 
|  | 84         udp_socket_->AllowAddressReuse() < 0 || | 
|  | 85         udp_socket_->Connect(remote_addr_) < 0) { | 
|  | 86       udp_socket_->Close(); | 
| 82       status_callback_.Run(TRANSPORT_SOCKET_ERROR); | 87       status_callback_.Run(TRANSPORT_SOCKET_ERROR); | 
| 83       LOG(ERROR) << "Failed to connect to remote address."; | 88       LOG(ERROR) << "Failed to connect to remote address."; | 
| 84       return; | 89       return; | 
| 85     } | 90     } | 
| 86     client_connected_ = true; | 91     client_connected_ = true; | 
| 87   } else { | 92   } else { | 
| 88     NOTREACHED() << "Either local or remote address has to be defined."; | 93     NOTREACHED() << "Either local or remote address has to be defined."; | 
| 89   } | 94   } | 
| 90   if (udp_socket_->SetSendBufferSize(send_buffer_size_) != net::OK) { | 95   if (udp_socket_->SetSendBufferSize(send_buffer_size_) != net::OK) { | 
| 91     LOG(WARNING) << "Failed to set socket send buffer size."; | 96     LOG(WARNING) << "Failed to set socket send buffer size."; | 
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 238   } | 243   } | 
| 239   ScheduleReceiveNextPacket(); | 244   ScheduleReceiveNextPacket(); | 
| 240 | 245 | 
| 241   if (!cb.is_null()) { | 246   if (!cb.is_null()) { | 
| 242     cb.Run(); | 247     cb.Run(); | 
| 243   } | 248   } | 
| 244 } | 249 } | 
| 245 | 250 | 
| 246 }  // namespace cast | 251 }  // namespace cast | 
| 247 }  // namespace media | 252 }  // namespace media | 
| OLD | NEW | 
|---|