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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); | 72 udp_socket_->AllowAddressReuse(); |
73 udp_socket_->SetMulticastLoopbackMode(true); | 73 udp_socket_->SetMulticastLoopbackMode(true); |
74 if (!IsEmpty(local_addr_)) { | 74 if (!IsEmpty(local_addr_)) { |
75 if (udp_socket_->Bind(local_addr_) < 0) { | 75 if (udp_socket_->Open(local_addr_.GetFamily()) < 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_->Connect(remote_addr_) < 0) { |
| 85 udp_socket_->Close(); |
82 status_callback_.Run(TRANSPORT_SOCKET_ERROR); | 86 status_callback_.Run(TRANSPORT_SOCKET_ERROR); |
83 LOG(ERROR) << "Failed to connect to remote address."; | 87 LOG(ERROR) << "Failed to connect to remote address."; |
84 return; | 88 return; |
85 } | 89 } |
86 client_connected_ = true; | 90 client_connected_ = true; |
87 } else { | 91 } else { |
88 NOTREACHED() << "Either local or remote address has to be defined."; | 92 NOTREACHED() << "Either local or remote address has to be defined."; |
89 } | 93 } |
90 if (udp_socket_->SetSendBufferSize(send_buffer_size_) != net::OK) { | 94 if (udp_socket_->SetSendBufferSize(send_buffer_size_) != net::OK) { |
91 LOG(WARNING) << "Failed to set socket send buffer size."; | 95 LOG(WARNING) << "Failed to set socket send buffer size."; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 242 } |
239 ScheduleReceiveNextPacket(); | 243 ScheduleReceiveNextPacket(); |
240 | 244 |
241 if (!cb.is_null()) { | 245 if (!cb.is_null()) { |
242 cb.Run(); | 246 cb.Run(); |
243 } | 247 } |
244 } | 248 } |
245 | 249 |
246 } // namespace cast | 250 } // namespace cast |
247 } // namespace media | 251 } // namespace media |
OLD | NEW |