| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  109   DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); |  109   DCHECK(io_thread_proxy_->RunsTasksOnCurrentThread()); | 
|  110  |  110  | 
|  111   // Loop while UdpSocket is delivering data synchronously.  When it responds |  111   // Loop while UdpSocket is delivering data synchronously.  When it responds | 
|  112   // with a "pending" status, break and expect this method to be called back in |  112   // with a "pending" status, break and expect this method to be called back in | 
|  113   // the future when a packet is ready. |  113   // the future when a packet is ready. | 
|  114   while (true) { |  114   while (true) { | 
|  115     if (length_or_status == net::ERR_IO_PENDING) { |  115     if (length_or_status == net::ERR_IO_PENDING) { | 
|  116       next_packet_.reset(new Packet(kMaxPacketSize)); |  116       next_packet_.reset(new Packet(kMaxPacketSize)); | 
|  117       recv_buf_ = new net::WrappedIOBuffer( |  117       recv_buf_ = new net::WrappedIOBuffer( | 
|  118           reinterpret_cast<char*>(&next_packet_->front())); |  118           reinterpret_cast<char*>(&next_packet_->front())); | 
|  119       length_or_status = udp_socket_->RecvFrom( |  119       length_or_status = | 
|  120           recv_buf_, |  120           udp_socket_->RecvFrom(recv_buf_.get(), | 
|  121           kMaxPacketSize, |  121                                 kMaxPacketSize, | 
|  122           &recv_addr_, |  122                                 &recv_addr_, | 
|  123           base::Bind(&UdpTransport::ReceiveNextPacket, |  123                                 base::Bind(&UdpTransport::ReceiveNextPacket, | 
|  124                      weak_factory_.GetWeakPtr())); |  124                                            weak_factory_.GetWeakPtr())); | 
|  125       if (length_or_status == net::ERR_IO_PENDING) { |  125       if (length_or_status == net::ERR_IO_PENDING) { | 
|  126         receive_pending_ = true; |  126         receive_pending_ = true; | 
|  127         return; |  127         return; | 
|  128       } |  128       } | 
|  129     } |  129     } | 
|  130  |  130  | 
|  131     // Note: At this point, either a packet is ready or an error has occurred. |  131     // Note: At this point, either a packet is ready or an error has occurred. | 
|  132     if (length_or_status < 0) { |  132     if (length_or_status < 0) { | 
|  133       VLOG(1) << "Failed to receive packet: Status code is " |  133       VLOG(1) << "Failed to receive packet: Status code is " | 
|  134               << length_or_status; |  134               << length_or_status; | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  189   int result; |  189   int result; | 
|  190   base::Callback<void(int)> callback = base::Bind(&UdpTransport::OnSent, |  190   base::Callback<void(int)> callback = base::Bind(&UdpTransport::OnSent, | 
|  191                                                   weak_factory_.GetWeakPtr(), |  191                                                   weak_factory_.GetWeakPtr(), | 
|  192                                                   buf, |  192                                                   buf, | 
|  193                                                   packet, |  193                                                   packet, | 
|  194                                                   cb); |  194                                                   cb); | 
|  195   if (client_connected_) { |  195   if (client_connected_) { | 
|  196     // If we called Connect() before we must call Write() instead of |  196     // If we called Connect() before we must call Write() instead of | 
|  197     // SendTo(). Otherwise on some platforms we might get |  197     // SendTo(). Otherwise on some platforms we might get | 
|  198     // ERR_SOCKET_IS_CONNECTED. |  198     // ERR_SOCKET_IS_CONNECTED. | 
|  199     result = udp_socket_->Write(buf, |  199     result = udp_socket_->Write( | 
|  200                                 static_cast<int>(packet->data.size()), |  200         buf.get(), static_cast<int>(packet->data.size()), callback); | 
|  201                                 callback); |  | 
|  202   } else if (!IsEmpty(remote_addr_)) { |  201   } else if (!IsEmpty(remote_addr_)) { | 
|  203     result = udp_socket_->SendTo(buf, |  202     result = udp_socket_->SendTo(buf.get(), | 
|  204                                  static_cast<int>(packet->data.size()), |  203                                  static_cast<int>(packet->data.size()), | 
|  205                                  remote_addr_, |  204                                  remote_addr_, | 
|  206                                  callback); |  205                                  callback); | 
|  207   } else { |  206   } else { | 
|  208     VLOG(1) << "Failed to send packet; socket is neither bound nor " |  207     VLOG(1) << "Failed to send packet; socket is neither bound nor " | 
|  209             << "connected."; |  208             << "connected."; | 
|  210     return true; |  209     return true; | 
|  211   } |  210   } | 
|  212  |  211  | 
|  213   if (result == net::ERR_IO_PENDING) { |  212   if (result == net::ERR_IO_PENDING) { | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|  234   } |  233   } | 
|  235   ScheduleReceiveNextPacket(); |  234   ScheduleReceiveNextPacket(); | 
|  236  |  235  | 
|  237   if (!cb.is_null()) { |  236   if (!cb.is_null()) { | 
|  238     cb.Run(); |  237     cb.Run(); | 
|  239   } |  238   } | 
|  240 } |  239 } | 
|  241  |  240  | 
|  242 }  // namespace cast |  241 }  // namespace cast | 
|  243 }  // namespace media |  242 }  // namespace media | 
| OLD | NEW |