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

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 tests 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/hash_tables.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
13 #include "base/win/object_watcher.h" 14 #include "base/win/object_watcher.h"
14 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
15 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
16 #include "net/base/rand_callback.h" 17 #include "net/base/rand_callback.h"
17 #include "net/base/ip_endpoint.h" 18 #include "net/base/ip_endpoint.h"
18 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
19 #include "net/base/net_log.h" 20 #include "net/base/net_log.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Sets corresponding flags in |socket_options_| to allow the socket 109 // Sets corresponding flags in |socket_options_| to allow the socket
109 // to share the local address to which the socket will be bound with 110 // to share the local address to which the socket will be bound with
110 // other processes. Should be called before Bind(). 111 // other processes. Should be called before Bind().
111 void AllowAddressReuse(); 112 void AllowAddressReuse();
112 113
113 // Sets corresponding flags in |socket_options_| to allow sending 114 // Sets corresponding flags in |socket_options_| to allow sending
114 // and receiving packets to and from broadcast addresses. Should be 115 // and receiving packets to and from broadcast addresses. Should be
115 // called before Bind(). 116 // called before Bind().
116 void AllowBroadcast(); 117 void AllowBroadcast();
117 118
119 // Join the multicast group.
120 // |group_address| is the group address to join, could be either
121 // IPv4 or IPv6 address.
122 int JoinGroup(const net::IPAddressNumber& group_address) const;
123
124 // Leave the multicast group.
125 // |group_address| is the group address to leave, could be either
126 // 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 int LeaveGroup(const net::IPAddressNumber& group_address) const;
131
132 // Set the time-to-live option for udp packets sent to the multicast
133 // group address. Initially this value is 1. Cannot be negative or
134 // more than 255.
135 int SetMulticastTimeToLive(int timeToLive);
mmenke 2013/04/12 21:07:41 time_to_live
Bei Zhang 2013/04/15 22:30:26 Done.
136
137 // Set the loopback flag for udp socket. If this flag is true, the host
138 // will receive package sent to the joined group from itself.
139 // Initially this value is true.
140 int SetMulticastLoopbackMode(bool loopback);
141
118 private: 142 private:
119 enum SocketOptions { 143 enum SocketOptions {
120 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, 144 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,
121 SOCKET_OPTION_BROADCAST = 1 << 1 145 SOCKET_OPTION_BROADCAST = 1 << 1
122 }; 146 };
123 147
124 class Core; 148 class Core;
125 149
126 void DoReadCallback(int rv); 150 void DoReadCallback(int rv);
127 void DoWriteCallback(int rv); 151 void DoWriteCallback(int rv);
(...skipping 25 matching lines...) Expand all
153 // Bind(). 177 // Bind().
154 int SetSocketOptions(); 178 int SetSocketOptions();
155 int DoBind(const IPEndPoint& address); 179 int DoBind(const IPEndPoint& address);
156 int RandomBind(const IPEndPoint& address); 180 int RandomBind(const IPEndPoint& address);
157 181
158 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| 182 // 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. 183 // to an IPEndPoint and writes it to |address|. Returns true on success.
160 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; 184 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const;
161 185
162 SOCKET socket_; 186 SOCKET socket_;
187 int sock_addr_family_;
mmenke 2013/04/12 21:07:41 This should be initialized in the constructor.
Bei Zhang 2013/04/15 22:30:26 Done.
163 188
164 // Bitwise-or'd combination of SocketOptions. Specifies the set of 189 // Bitwise-or'd combination of SocketOptions. Specifies the set of
165 // options that should be applied to |socket_| before Bind(). 190 // options that should be applied to |socket_| before Bind().
166 int socket_options_; 191 int socket_options_;
167 192
193 // Multicast socket options cached for SetSocketOption.
194 // Cannot be used after Bind().
195 int multicast_time_to_live_;
196 bool multicast_loopback_mode_;
mmenke 2013/04/12 21:07:41 These, too.
Bei Zhang 2013/04/15 22:30:26 Done.
197
168 // How to do source port binding, used only when UDPSocket is part of 198 // How to do source port binding, used only when UDPSocket is part of
169 // UDPClientSocket, since UDPServerSocket provides Bind. 199 // UDPClientSocket, since UDPServerSocket provides Bind.
170 DatagramSocket::BindType bind_type_; 200 DatagramSocket::BindType bind_type_;
171 201
172 // PRNG function for generating port numbers. 202 // PRNG function for generating port numbers.
173 RandIntCallback rand_int_cb_; 203 RandIntCallback rand_int_cb_;
174 204
175 // These are mutable since they're just cached copies to make 205 // These are mutable since they're just cached copies to make
176 // GetPeerAddress/GetLocalAddress smarter. 206 // GetPeerAddress/GetLocalAddress smarter.
177 mutable scoped_ptr<IPEndPoint> local_address_; 207 mutable scoped_ptr<IPEndPoint> local_address_;
(...skipping 17 matching lines...) Expand all
195 CompletionCallback write_callback_; 225 CompletionCallback write_callback_;
196 226
197 BoundNetLog net_log_; 227 BoundNetLog net_log_;
198 228
199 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); 229 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin);
200 }; 230 };
201 231
202 } // namespace net 232 } // namespace net
203 233
204 #endif // NET_UDP_UDP_SOCKET_WIN_H_ 234 #endif // NET_UDP_UDP_SOCKET_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698