summaryrefslogtreecommitdiffstats
path: root/net/udp/udp_socket_win.h
diff options
context:
space:
mode:
authorikarienator@chromium.org <ikarienator@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-30 00:53:18 +0000
committerikarienator@chromium.org <ikarienator@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-30 00:53:18 +0000
commit5f01ce2a2ae37642c94d7be68f9b32423f69eddd (patch)
tree7ab6ea1cb8fcaec943a64ee4cb530a5f68a5a490 /net/udp/udp_socket_win.h
parentcd756659546ef1bebf9f939b1bba4a1dd64be552 (diff)
downloadchromium_src-5f01ce2a2ae37642c94d7be68f9b32423f69eddd.zip
chromium_src-5f01ce2a2ae37642c94d7be68f9b32423f69eddd.tar.gz
chromium_src-5f01ce2a2ae37642c94d7be68f9b32423f69eddd.tar.bz2
Introduce Multicast Socket API
Allow Chrome Apps developer to receive multicast socket packets by exposing join/leave group ability to UDP socket. Introducing: 1. chrome.socket.joinGroup / chrome.socket.leaveGroup / chrome.socket.getJoinedGroups to manipulate multicast group membership. 2. Socket permission 'udp-multicast-membership'. 3. chrome.socket.setMulticastTimeToLive / chrome.socket.setMulticastLoopbackMode to control the multicast packet sending for UDP sender. To expose the ability of manipulating multicast group membership and controlling multicast packet sending, new methods are added into network stack (net::UDPSocket class): 1. JoinGroup/LeaveGroup 2. SetMulticastTimeToLive/SetMulticastLoopbackMode To demo the ability, a demo app is created: https://github.com/GoogleChrome/chrome-app-samples/pull/92 TEST=Open the demo app at /chrome-app-samples/multicast in two machines of the same network. Open them and chat, they can talk to each other. NOTRY=true BUG=140681 Review URL: https://chromiumcodereview.appspot.com/12684008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197192 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/udp/udp_socket_win.h')
-rw-r--r--net/udp/udp_socket_win.h46
1 files changed, 44 insertions, 2 deletions
diff --git a/net/udp/udp_socket_win.h b/net/udp/udp_socket_win.h
index ce17050..807b403 100644
--- a/net/udp/udp_socket_win.h
+++ b/net/udp/udp_socket_win.h
@@ -115,10 +115,47 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) {
// called before Bind().
void AllowBroadcast();
+ // Join the multicast group.
+ // |group_address| is the group address to join, could be either
+ // an IPv4 or IPv6 address.
+ // Return a network error code.
+ int JoinGroup(const IPAddressNumber& group_address) const;
+
+ // Leave the multicast group.
+ // |group_address| is the group address to leave, could be either
+ // an IPv4 or IPv6 address. If the socket hasn't joined the group,
+ // it will be ignored.
+ // It's optional to leave the multicast group before destroying
+ // the socket. It will be done by the OS.
+ // Return a network error code.
+ int LeaveGroup(const IPAddressNumber& group_address) const;
+
+ // Set the time-to-live option for UDP packets sent to the multicast
+ // group address. The default value of this option is 1.
+ // Cannot be negative or more than 255.
+ // Should be called before Bind().
+ int SetMulticastTimeToLive(int time_to_live);
+
+ // Set the loopback flag for UDP socket. If this flag is true, the host
+ // will receive packets sent to the joined group from itself.
+ // The default value of this option is true.
+ // Should be called before Bind().
+ //
+ // Note: the behavior of |SetMulticastLoopbackMode| is slightly
+ // different between Windows and Unix-like systems. The inconsistency only
+ // happens when there are more than one applications on the same host
+ // joined to the same multicast group while having different settings on
+ // multicast loopback mode. On Windows, the applications with loopback off
+ // will not RECEIVE the loopback packets; while on Unix-like systems, the
+ // applications with loopback off will not SEND the loopback packets to
+ // other applications on the same host. See MSDN: http://goo.gl/6vqbj
+ int SetMulticastLoopbackMode(bool loopback);
+
private:
enum SocketOptions {
- SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,
- SOCKET_OPTION_BROADCAST = 1 << 1
+ SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,
+ SOCKET_OPTION_BROADCAST = 1 << 1,
+ SOCKET_OPTION_MULTICAST_LOOP = 1 << 2
};
class Core;
@@ -160,11 +197,16 @@ class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) {
bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const;
SOCKET socket_;
+ int addr_family_;
// Bitwise-or'd combination of SocketOptions. Specifies the set of
// options that should be applied to |socket_| before Bind().
int socket_options_;
+ // Multicast socket options cached for SetSocketOption.
+ // Cannot be used after Bind().
+ int multicast_time_to_live_;
+
// How to do source port binding, used only when UDPSocket is part of
// UDPClientSocket, since UDPServerSocket provides Bind.
DatagramSocket::BindType bind_type_;