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

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: Fixed Win 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.h ('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..03c724ee930760b5026bf8fbe6ce0a9ae4d9ef21 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),
+ socket_options_(0),
bind_type_(bind_type),
rand_int_cb_(rand_int_cb),
ALLOW_THIS_IN_INITIALIZER_LIST(read_delegate_(this)),
@@ -229,6 +230,9 @@ int UDPSocketWin::Bind(const IPEndPoint& address) {
int rv = CreateSocket(address);
if (rv < 0)
return rv;
+ rv = SetSocketOptions();
+ if (rv < 0)
+ return rv;
rv = DoBind(address);
if (rv < 0)
return rv;
@@ -260,6 +264,20 @@ bool UDPSocketWin::SetSendBufferSize(int32 size) {
return rv == 0;
}
+void UDPSocketWin::AllowAddressReuse() {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!is_connected());
+
+ socket_options_ |= SOCKET_OPTION_REUSE_ADDRESS;
+}
+
+void UDPSocketWin::AllowBroadcast() {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!is_connected());
+
+ socket_options_ |= SOCKET_OPTION_BROADCAST;
+}
+
void UDPSocketWin::DoReadCallback(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING);
DCHECK(!read_callback_.is_null());
@@ -431,6 +449,25 @@ int UDPSocketWin::InternalSendTo(IOBuffer* buf, int buf_len,
return ERR_IO_PENDING;
}
+int UDPSocketWin::SetSocketOptions() {
+ BOOL true_value = 1;
+ if (socket_options_ & SOCKET_OPTION_REUSE_ADDRESS) {
+ int rv = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR,
+ reinterpret_cast<const char*>(&true_value),
+ sizeof(true_value));
+ if (rv < 0)
+ return MapSystemError(errno);
+ }
+ if (socket_options_ & SOCKET_OPTION_BROADCAST) {
+ int 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.h ('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