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

Side by Side Diff: net/udp/udp_socket_win.h

Issue 12684008: Multicast socket API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows build Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_UDP_UDP_SOCKET_WIN_H_ 5 #ifndef NET_UDP_UDP_SOCKET_WIN_H_
6 #define NET_UDP_UDP_SOCKET_WIN_H_ 6 #define NET_UDP_UDP_SOCKET_WIN_H_
7 7
8 #include <winsock2.h> 8 #include <winsock2.h>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Sets corresponding flags in |socket_options_| to allow the socket 108 // Sets corresponding flags in |socket_options_| to allow the socket
109 // to share the local address to which the socket will be bound with 109 // to share the local address to which the socket will be bound with
110 // other processes. Should be called before Bind(). 110 // other processes. Should be called before Bind().
111 void AllowAddressReuse(); 111 void AllowAddressReuse();
112 112
113 // Sets corresponding flags in |socket_options_| to allow sending 113 // Sets corresponding flags in |socket_options_| to allow sending
114 // and receiving packets to and from broadcast addresses. Should be 114 // and receiving packets to and from broadcast addresses. Should be
115 // called before Bind(). 115 // called before Bind().
116 void AllowBroadcast(); 116 void AllowBroadcast();
117 117
118 // Join the multicast group.
119 // |group_address| is the group address to join, could be either
120 // an IPv4 or IPv6 address.
121 // Return a network error code.
122 int JoinGroup(const IPAddressNumber& group_address) const;
123
124 // Leave the multicast group.
125 // |group_address| is the group address to leave, could be either
126 // an IPv4 or IPv6 address. If the socket hasn't joined the group,
127 // it will be ignored.
128 // It's optional to leave the multicast group before destroying
129 // the socket. It will be done by the OS.
130 // Return a network error code.
131 int LeaveGroup(const IPAddressNumber& group_address) const;
132
133 // Set the time-to-live option for UDP packets sent to the multicast
134 // group address. The default value of this option is 1.
135 // Cannot be negative or more than 255.
136 // Should be called before Bind().
137 int SetMulticastTimeToLive(int time_to_live);
138
139 // Set the loopback flag for UDP socket. If this flag is true, the host
140 // will receive packets sent to the joined group from itself.
141 // The default value of this option is true.
142 // Should be called before Bind().
143 int SetMulticastLoopbackMode(bool loopback);
144
118 private: 145 private:
119 enum SocketOptions { 146 enum SocketOptions {
120 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, 147 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,
121 SOCKET_OPTION_BROADCAST = 1 << 1 148 SOCKET_OPTION_BROADCAST = 1 << 1,
149 SOCKET_OPTION_MULTICAST_LOOP = 1 << 2
122 }; 150 };
123 151
124 class Core; 152 class Core;
125 153
126 void DoReadCallback(int rv); 154 void DoReadCallback(int rv);
127 void DoWriteCallback(int rv); 155 void DoWriteCallback(int rv);
128 void DidCompleteRead(); 156 void DidCompleteRead();
129 void DidCompleteWrite(); 157 void DidCompleteWrite();
130 158
131 // Handles stats and logging. |result| is the number of bytes transferred, on 159 // Handles stats and logging. |result| is the number of bytes transferred, on
(...skipping 21 matching lines...) Expand all
153 // Bind(). 181 // Bind().
154 int SetSocketOptions(); 182 int SetSocketOptions();
155 int DoBind(const IPEndPoint& address); 183 int DoBind(const IPEndPoint& address);
156 int RandomBind(const IPEndPoint& address); 184 int RandomBind(const IPEndPoint& address);
157 185
158 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| 186 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_|
159 // to an IPEndPoint and writes it to |address|. Returns true on success. 187 // to an IPEndPoint and writes it to |address|. Returns true on success.
160 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; 188 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const;
161 189
162 SOCKET socket_; 190 SOCKET socket_;
191 int addr_family_;
163 192
164 // Bitwise-or'd combination of SocketOptions. Specifies the set of 193 // Bitwise-or'd combination of SocketOptions. Specifies the set of
165 // options that should be applied to |socket_| before Bind(). 194 // options that should be applied to |socket_| before Bind().
166 int socket_options_; 195 int socket_options_;
167 196
197 // Multicast socket options cached for SetSocketOption.
198 // Cannot be used after Bind().
199 int multicast_time_to_live_;
200
168 // How to do source port binding, used only when UDPSocket is part of 201 // How to do source port binding, used only when UDPSocket is part of
169 // UDPClientSocket, since UDPServerSocket provides Bind. 202 // UDPClientSocket, since UDPServerSocket provides Bind.
170 DatagramSocket::BindType bind_type_; 203 DatagramSocket::BindType bind_type_;
171 204
172 // PRNG function for generating port numbers. 205 // PRNG function for generating port numbers.
173 RandIntCallback rand_int_cb_; 206 RandIntCallback rand_int_cb_;
174 207
175 // These are mutable since they're just cached copies to make 208 // These are mutable since they're just cached copies to make
176 // GetPeerAddress/GetLocalAddress smarter. 209 // GetPeerAddress/GetLocalAddress smarter.
177 mutable scoped_ptr<IPEndPoint> local_address_; 210 mutable scoped_ptr<IPEndPoint> local_address_;
(...skipping 17 matching lines...) Expand all
195 CompletionCallback write_callback_; 228 CompletionCallback write_callback_;
196 229
197 BoundNetLog net_log_; 230 BoundNetLog net_log_;
198 231
199 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); 232 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin);
200 }; 233 };
201 234
202 } // namespace net 235 } // namespace net
203 236
204 #endif // NET_UDP_UDP_SOCKET_WIN_H_ 237 #endif // NET_UDP_UDP_SOCKET_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698