Commit 497cb60f authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Add broadcast to network::mojom::UDPSocketOptions.

It turns out that on OSX, broadcast must be set on a UDP socket before
binding a socket when reusing an address that already has a broadcast
socket bound to it. Otherwise, the bind() call will fail.

Bug: 848078
Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: I41f2bb6085a9be1dc42c18483a85766d4b3d46ac
Reviewed-on: https://chromium-review.googlesource.com/1188617
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarHelen Li <xunjieli@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586016}
parent 8d28b7e1
......@@ -15,13 +15,22 @@ import "net/interfaces/ip_endpoint.mojom";
struct UDPSocketOptions {
// If true, this enables SO_REUSEADDR on the underlying socket.
bool allow_address_reuse = false;
// It true, allows sending and receiving packets to and from broadcast
// addresses. It's recommended this be used instead of SetBroadcast(), as
// Bind() may fail on some platforms when reusing a UDP port and broadcast
// is not enabled when the socket is created.
bool allow_broadcast = false;
// Sets interface to use for multicast. Default value is 0, in which case the
// default interface is used.
uint32 multicast_interface = 0;
// Sets the time-to-live option for UDP packets sent to the multicast
// group address. The default value of this option is 1. Cannot be more than
// 255.
uint32 multicast_time_to_live = 1;
// Sets the loopback flag for UDP socket. If this flag is true and the socket
// joins a group through JoinGroup(), the socket will receive packets sent to
// the joined group from itself. The default value of this option is true.
......@@ -35,6 +44,7 @@ struct UDPSocketOptions {
// applications with loopback off will not SEND the loopback packets to
// other applications on the same host. See MSDN: http://goo.gl/6vqbj
bool multicast_loopback_mode = true;
// Sets the OS send buffer size (in bytes) for the socket. This is the
// SO_SNDBUF socket option. This socket option matters less for UDP socket (as
// compared to TCP), because in theory all UDP data written to the kernel
......@@ -42,6 +52,7 @@ struct UDPSocketOptions {
// buffer send data. Default value is 0, in which case, OS's default value
// will be used.
int32 send_buffer_size = 0;
// Sets the OS receive buffer size (in bytes) for the socket. This is the
// SO_RCVBUF socket option. The kernel allocates this much to hold the data
// arriving into this socket between the time when data arrives over the
......
......@@ -115,6 +115,8 @@ class SocketWrapperImpl : public UDPSocket::SocketWrapper {
int result = net::OK;
if (options->allow_address_reuse)
result = socket_.AllowAddressReuse();
if (result == net::OK && options->allow_broadcast)
result = socket_.SetBroadcast(true);
if (result == net::OK && options->multicast_interface != 0)
result = socket_.SetMulticastInterface(options->multicast_interface);
if (result == net::OK && !options->multicast_loopback_mode) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment