Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: net/udp/udp_socket_win.cc

Issue 10739002: Added broadcasting feature to UDP server sockets. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added MacOS specific code. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/udp/udp_socket_libevent.cc ('K') | « net/udp/udp_socket_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/udp/udp_socket_win.cc
diff --git a/net/udp/udp_socket_win.cc b/net/udp/udp_socket_win.cc
index a7a11bf32f17e6829eab71273fb1f1556d618f86..2f25a231a0163c7c0da945e8a759de4850ed4b1a 100644
--- a/net/udp/udp_socket_win.cc
+++ b/net/udp/udp_socket_win.cc
@@ -46,6 +46,7 @@ UDPSocketWin::UDPSocketWin(DatagramSocket::BindType bind_type,
net::NetLog* net_log,
const net::NetLog::Source& source)
: socket_(INVALID_SOCKET),
+ allow_broadcast_(false),
bind_type_(bind_type),
rand_int_cb_(rand_int_cb),
ALLOW_THIS_IN_INITIALIZER_LIST(read_delegate_(this)),
@@ -229,6 +230,11 @@ int UDPSocketWin::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;
@@ -260,6 +266,13 @@ bool UDPSocketWin::SetSendBufferSize(int32 size) {
return rv == 0;
}
+void UDPSocketWin::AllowBroadcast() {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!is_connected());
+
+ allow_broadcast_ = true;
+}
+
void UDPSocketWin::DoReadCallback(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING);
DCHECK(!read_callback_.is_null());
@@ -431,6 +444,21 @@ int UDPSocketWin::InternalSendTo(IOBuffer* buf, int buf_len,
return ERR_IO_PENDING;
}
+int UDPSocketWin::DoBroadcast() {
+ int true_value = 1;
wtc 2012/07/11 18:26:37 It looks nicer to use the BOOL type here: http://m
ygorshenin1 2012/07/12 09:28:08 Done.
+ int rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR,
+ reinterpret_cast<const char*>(&true_value),
+ sizeof(true_value));
+ if (rv < 0)
+ return MapSystemError(errno);
+ 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 UDPSocketWin::DoBind(const IPEndPoint& address) {
SockaddrStorage storage;
if (!address.ToSockAddr(storage.addr, &storage.addr_len))
« net/udp/udp_socket_libevent.cc ('K') | « net/udp/udp_socket_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698