Index: net/udp/udp_socket_libevent.cc |
diff --git a/net/udp/udp_socket_libevent.cc b/net/udp/udp_socket_libevent.cc |
index bb1cf91ede1fac18c855dca63eb4b12d701a9244..d4c61281bbe89ba4ffce125b7d8d5dd9b176add2 100644 |
--- a/net/udp/udp_socket_libevent.cc |
+++ b/net/udp/udp_socket_libevent.cc |
@@ -41,6 +41,7 @@ UDPSocketLibevent::UDPSocketLibevent( |
net::NetLog* net_log, |
const net::NetLog::Source& source) |
: socket_(kInvalidSocket), |
+ allow_broadcast_(false), |
bind_type_(bind_type), |
rand_int_cb_(rand_int_cb), |
read_watcher_(this), |
@@ -251,6 +252,11 @@ int UDPSocketLibevent::Bind(const IPEndPoint& address) { |
int rv = CreateSocket(address); |
if (rv < 0) |
return rv; |
+ if (allow_broadcast_) { |
+ rv = DoBroadcast(); |
+ if (rv < 0) |
+ return rv; |
+ } |
rv = DoBind(address); |
if (rv < 0) |
return rv; |
@@ -274,6 +280,13 @@ bool UDPSocketLibevent::SetSendBufferSize(int32 size) { |
return rv == 0; |
} |
+void UDPSocketLibevent::AllowBroadcast() { |
+ DCHECK(CalledOnValidThread()); |
+ DCHECK(!is_connected()); |
+ |
+ allow_broadcast_ = true; |
+} |
+ |
void UDPSocketLibevent::DoReadCallback(int rv) { |
DCHECK_NE(rv, ERR_IO_PENDING); |
DCHECK(!read_callback_.is_null()); |
@@ -430,6 +443,28 @@ int UDPSocketLibevent::InternalSendTo(IOBuffer* buf, int buf_len, |
return result; |
} |
+int UDPSocketLibevent::DoBroadcast() { |
+ int true_value = 1; |
+ int rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, |
+ reinterpret_cast<const char*>(&true_value), |
wtc
2012/07/11 18:26:37
Since the fourth argument to setsockopt is a const
ygorshenin1
2012/07/12 09:28:08
Done.
|
+ sizeof(true_value)); |
+ if (rv < 0) |
+ return MapSystemError(errno); |
+#if defined(OS_MACOSX) |
wtc
2012/07/11 18:26:37
If SO_REUSEPORT is defined as a macro (rather than
ygorshenin1
2012/07/12 09:28:08
Done.
|
+ rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEPORT, |
+ reinterpret_cast<const char*>(&true_value), |
+ sizeof(true_value)); |
+ if (rv < 0) |
+ return MapSystemError(errno); |
+#endif |
+ rv = setsockopt(socket_, SOL_SOCKET, SO_BROADCAST, |
+ reinterpret_cast<const char*>(&true_value), |
+ sizeof(true_value)); |
+ if (rv < 0) |
+ return MapSystemError(errno); |
+ return OK; |
+} |
+ |
int UDPSocketLibevent::DoBind(const IPEndPoint& address) { |
SockaddrStorage storage; |
if (!address.ToSockAddr(storage.addr, &storage.addr_len)) |