OLD | NEW |
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 Loading... |
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 // |
| 144 // Note: the behavior of |SetMulticastLoopbackMode| is slightly |
| 145 // different between Windows and Unix-like systems. The inconsistency only |
| 146 // happens when there are more than one applications on the same host |
| 147 // joined to the same multicast group while having different settings on |
| 148 // multicast loopback mode. On Windows, the applications with loopback off |
| 149 // will not RECEIVE the loopback packets; while on Unix-like systems, the |
| 150 // applications with loopback off will not SEND the loopback packets to |
| 151 // other applications on the same host. See MSDN: http://goo.gl/6vqbj |
| 152 int SetMulticastLoopbackMode(bool loopback); |
| 153 |
118 private: | 154 private: |
119 enum SocketOptions { | 155 enum SocketOptions { |
120 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, | 156 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |
121 SOCKET_OPTION_BROADCAST = 1 << 1 | 157 SOCKET_OPTION_BROADCAST = 1 << 1, |
| 158 SOCKET_OPTION_MULTICAST_LOOP = 1 << 2 |
122 }; | 159 }; |
123 | 160 |
124 class Core; | 161 class Core; |
125 | 162 |
126 void DoReadCallback(int rv); | 163 void DoReadCallback(int rv); |
127 void DoWriteCallback(int rv); | 164 void DoWriteCallback(int rv); |
128 void DidCompleteRead(); | 165 void DidCompleteRead(); |
129 void DidCompleteWrite(); | 166 void DidCompleteWrite(); |
130 | 167 |
131 // Handles stats and logging. |result| is the number of bytes transferred, on | 168 // Handles stats and logging. |result| is the number of bytes transferred, on |
(...skipping 21 matching lines...) Expand all Loading... |
153 // Bind(). | 190 // Bind(). |
154 int SetSocketOptions(); | 191 int SetSocketOptions(); |
155 int DoBind(const IPEndPoint& address); | 192 int DoBind(const IPEndPoint& address); |
156 int RandomBind(const IPEndPoint& address); | 193 int RandomBind(const IPEndPoint& address); |
157 | 194 |
158 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| | 195 // 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. | 196 // to an IPEndPoint and writes it to |address|. Returns true on success. |
160 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; | 197 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; |
161 | 198 |
162 SOCKET socket_; | 199 SOCKET socket_; |
| 200 int addr_family_; |
163 | 201 |
164 // Bitwise-or'd combination of SocketOptions. Specifies the set of | 202 // Bitwise-or'd combination of SocketOptions. Specifies the set of |
165 // options that should be applied to |socket_| before Bind(). | 203 // options that should be applied to |socket_| before Bind(). |
166 int socket_options_; | 204 int socket_options_; |
167 | 205 |
| 206 // Multicast socket options cached for SetSocketOption. |
| 207 // Cannot be used after Bind(). |
| 208 int multicast_time_to_live_; |
| 209 |
168 // How to do source port binding, used only when UDPSocket is part of | 210 // How to do source port binding, used only when UDPSocket is part of |
169 // UDPClientSocket, since UDPServerSocket provides Bind. | 211 // UDPClientSocket, since UDPServerSocket provides Bind. |
170 DatagramSocket::BindType bind_type_; | 212 DatagramSocket::BindType bind_type_; |
171 | 213 |
172 // PRNG function for generating port numbers. | 214 // PRNG function for generating port numbers. |
173 RandIntCallback rand_int_cb_; | 215 RandIntCallback rand_int_cb_; |
174 | 216 |
175 // These are mutable since they're just cached copies to make | 217 // These are mutable since they're just cached copies to make |
176 // GetPeerAddress/GetLocalAddress smarter. | 218 // GetPeerAddress/GetLocalAddress smarter. |
177 mutable scoped_ptr<IPEndPoint> local_address_; | 219 mutable scoped_ptr<IPEndPoint> local_address_; |
(...skipping 17 matching lines...) Expand all Loading... |
195 CompletionCallback write_callback_; | 237 CompletionCallback write_callback_; |
196 | 238 |
197 BoundNetLog net_log_; | 239 BoundNetLog net_log_; |
198 | 240 |
199 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); | 241 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); |
200 }; | 242 }; |
201 | 243 |
202 } // namespace net | 244 } // namespace net |
203 | 245 |
204 #endif // NET_UDP_UDP_SOCKET_WIN_H_ | 246 #endif // NET_UDP_UDP_SOCKET_WIN_H_ |
OLD | NEW |