diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 14:28:30 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 14:28:30 +0000 |
commit | 9d68faf4eef2a17f7c89a40d8bd2e579f2c53bc2 (patch) | |
tree | 667355568d32456f21273d890cdd48ec172df3c4 /media/cast | |
parent | ab54bd65701f3e6927cc4dcc1d04840e7e14a0b2 (diff) | |
download | chromium_src-9d68faf4eef2a17f7c89a40d8bd2e579f2c53bc2.zip chromium_src-9d68faf4eef2a17f7c89a40d8bd2e579f2c53bc2.tar.gz chromium_src-9d68faf4eef2a17f7c89a40d8bd2e579f2c53bc2.tar.bz2 |
Cast: If a UdpSocket is connected then call Write instead of SendTo
On some platforms calling SendTo() with a connected UDP socket results
in an error. So call Write() instead of SendTo().
Tested this with cast_sender_app and cast_receiver_app on Linux.
Review URL: https://codereview.chromium.org/181593011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253809 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/cast')
-rw-r--r-- | media/cast/transport/transport/udp_transport.cc | 18 | ||||
-rw-r--r-- | media/cast/transport/transport/udp_transport.h | 1 |
2 files changed, 18 insertions, 1 deletions
diff --git a/media/cast/transport/transport/udp_transport.cc b/media/cast/transport/transport/udp_transport.cc index 936939d..faea498 100644 --- a/media/cast/transport/transport/udp_transport.cc +++ b/media/cast/transport/transport/udp_transport.cc @@ -52,6 +52,7 @@ UdpTransport::UdpTransport( net_log, net::NetLog::Source())), send_pending_(false), + client_connected_(false), status_callback_(status_callback), weak_factory_(this) { DCHECK(!IsEmpty(local_end_point) || !IsEmpty(remote_end_point)); @@ -78,6 +79,7 @@ void UdpTransport::StartReceiving( LOG(ERROR) << "Failed to connect to remote address."; return; } + client_connected_ = true; } else { NOTREACHED() << "Either local or remote address has to be defined."; } @@ -149,11 +151,25 @@ bool UdpTransport::SendPacket(const Packet& packet) { scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(static_cast<int>(packet.size())); memcpy(buf->data(), &packet[0], packet.size()); - int ret = udp_socket_->SendTo( + + int ret; + if (client_connected_) { + // If we called Connect() before we must call Write() instead of + // SendTo(). Otherwise on some platforms we might get + // ERR_SOCKET_IS_CONNECTED. + ret = udp_socket_->Write( + buf, + static_cast<int>(packet.size()), + base::Bind(&UdpTransport::OnSent, weak_factory_.GetWeakPtr(), buf)); + } else if (!IsEmpty(remote_addr_)) { + ret = udp_socket_->SendTo( buf, static_cast<int>(packet.size()), remote_addr_, base::Bind(&UdpTransport::OnSent, weak_factory_.GetWeakPtr(), buf)); + } else { + return false; + } if (ret == net::ERR_IO_PENDING) send_pending_ = true; // When ok, will return a positive value equal the number of bytes sent. diff --git a/media/cast/transport/transport/udp_transport.h b/media/cast/transport/transport/udp_transport.h index 31e1618..d316416 100644 --- a/media/cast/transport/transport/udp_transport.h +++ b/media/cast/transport/transport/udp_transport.h @@ -63,6 +63,7 @@ class UdpTransport : public PacketSender { net::IPEndPoint remote_addr_; const scoped_ptr<net::UDPSocket> udp_socket_; bool send_pending_; + bool client_connected_; scoped_ptr<Packet> next_packet_; scoped_refptr<net::WrappedIOBuffer> recv_buf_; net::IPEndPoint recv_addr_; |