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 <qos2.h> | 8 #include <qos2.h> |
9 #include <winsock2.h> | 9 #include <winsock2.h> |
10 | 10 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Returns true if the socket is already connected or bound. | 106 // Returns true if the socket is already connected or bound. |
107 bool is_connected() const { return socket_ != INVALID_SOCKET; } | 107 bool is_connected() const { return socket_ != INVALID_SOCKET; } |
108 | 108 |
109 const BoundNetLog& NetLog() const { return net_log_; } | 109 const BoundNetLog& NetLog() const { return net_log_; } |
110 | 110 |
111 // Sets corresponding flags in |socket_options_| to allow the socket | 111 // Sets corresponding flags in |socket_options_| to allow the socket |
112 // to share the local address to which the socket will be bound with | 112 // to share the local address to which the socket will be bound with |
113 // other processes. Should be called before Bind(). | 113 // other processes. Should be called before Bind(). |
114 void AllowAddressReuse(); | 114 void AllowAddressReuse(); |
115 | 115 |
116 // Sets corresponding flags in |socket_options_| to allow sending | 116 // Sets corresponding flags in |socket_options_| to allow or disallow |
117 // and receiving packets to and from broadcast addresses. Should be | 117 // sending and receiving packets to and from broadcast addresses. |
118 // called before Bind(). | 118 // Returns a net error code. |
119 void AllowBroadcast(); | 119 int SetBroadcast(bool broadcast); |
120 | 120 |
121 // Join the multicast group. | 121 // Join the multicast group. |
122 // |group_address| is the group address to join, could be either | 122 // |group_address| is the group address to join, could be either |
123 // an IPv4 or IPv6 address. | 123 // an IPv4 or IPv6 address. |
124 // Return a network error code. | 124 // Return a network error code. |
125 int JoinGroup(const IPAddressNumber& group_address) const; | 125 int JoinGroup(const IPAddressNumber& group_address) const; |
126 | 126 |
127 // Leave the multicast group. | 127 // Leave the multicast group. |
128 // |group_address| is the group address to leave, could be either | 128 // |group_address| is the group address to leave, could be either |
129 // an IPv4 or IPv6 address. If the socket hasn't joined the group, | 129 // an IPv4 or IPv6 address. If the socket hasn't joined the group, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // do anything on some platforms. | 164 // do anything on some platforms. |
165 int SetDiffServCodePoint(DiffServCodePoint dscp); | 165 int SetDiffServCodePoint(DiffServCodePoint dscp); |
166 | 166 |
167 // Resets the thread to be used for thread-safety checks. | 167 // Resets the thread to be used for thread-safety checks. |
168 void DetachFromThread(); | 168 void DetachFromThread(); |
169 | 169 |
170 private: | 170 private: |
171 enum SocketOptions { | 171 enum SocketOptions { |
172 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, | 172 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |
173 SOCKET_OPTION_BROADCAST = 1 << 1, | 173 SOCKET_OPTION_BROADCAST = 1 << 1, |
174 SOCKET_OPTION_MULTICAST_LOOP = 1 << 2 | 174 SOCKET_OPTION_MULTICAST_LOOP = 1 << 2, |
| 175 SOCKET_OPTION_RCVBUF_SIZE = 1 << 3, |
| 176 SOCKET_OPTION_SNDBUF_SIZE = 1 << 4 |
175 }; | 177 }; |
176 | 178 |
177 class Core; | 179 class Core; |
178 | 180 |
179 void DoReadCallback(int rv); | 181 void DoReadCallback(int rv); |
180 void DoWriteCallback(int rv); | 182 void DoWriteCallback(int rv); |
181 void DidCompleteRead(); | 183 void DidCompleteRead(); |
182 void DidCompleteWrite(); | 184 void DidCompleteWrite(); |
183 | 185 |
184 // Handles stats and logging. |result| is the number of bytes transferred, on | 186 // Handles stats and logging. |result| is the number of bytes transferred, on |
(...skipping 11 matching lines...) Expand all Loading... |
196 int SendToOrWrite(IOBuffer* buf, | 198 int SendToOrWrite(IOBuffer* buf, |
197 int buf_len, | 199 int buf_len, |
198 const IPEndPoint* address, | 200 const IPEndPoint* address, |
199 const CompletionCallback& callback); | 201 const CompletionCallback& callback); |
200 | 202 |
201 int InternalConnect(const IPEndPoint& address); | 203 int InternalConnect(const IPEndPoint& address); |
202 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 204 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
203 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 205 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
204 | 206 |
205 // Applies |socket_options_| to |socket_|. Should be called before | 207 // Applies |socket_options_| to |socket_|. Should be called before |
206 // Bind(). | 208 // DoBind(). |
207 int SetSocketOptions(); | 209 int SetSocketOptions(); |
| 210 int AllowAddressReuseInternal(); |
| 211 int SetBroadcastInternal(bool broadcast); |
| 212 int SetReceiveBufferSizeInternal(int32 size); |
| 213 int SetSendBufferSizeInternal(int32 size); |
208 int DoBind(const IPEndPoint& address); | 214 int DoBind(const IPEndPoint& address); |
209 // Binds to a random port on |address|. | 215 // Binds to a random port on |address|. |
210 int RandomBind(const IPAddressNumber& address); | 216 int RandomBind(const IPAddressNumber& address); |
211 | 217 |
212 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| | 218 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| |
213 // to an IPEndPoint and writes it to |address|. Returns true on success. | 219 // to an IPEndPoint and writes it to |address|. Returns true on success. |
214 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; | 220 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; |
215 | 221 |
216 SOCKET socket_; | 222 SOCKET socket_; |
217 int addr_family_; | 223 int addr_family_; |
218 | 224 |
219 // Bitwise-or'd combination of SocketOptions. Specifies the set of | 225 // Bitwise-or'd combination of SocketOptions. Specifies the set of |
220 // options that should be applied to |socket_| before Bind(). | 226 // options that should be applied to |socket_| before Bind(). |
221 int socket_options_; | 227 int socket_options_; |
222 | 228 |
| 229 // Locally cacned value of buffer size. These are automatically applied |
| 230 // when SetSocketOptions() is called. |
| 231 int32 rcvbuf_size_; |
| 232 int32 sndbuf_size_; |
| 233 |
223 // Multicast interface. | 234 // Multicast interface. |
224 uint32 multicast_interface_; | 235 uint32 multicast_interface_; |
225 | 236 |
226 // Multicast socket options cached for SetSocketOption. | 237 // Multicast socket options cached for SetSocketOption. |
227 // Cannot be used after Bind(). | 238 // Cannot be used after Bind(). |
228 int multicast_time_to_live_; | 239 int multicast_time_to_live_; |
229 | 240 |
230 // How to do source port binding, used only when UDPSocket is part of | 241 // How to do source port binding, used only when UDPSocket is part of |
231 // UDPClientSocket, since UDPServerSocket provides Bind. | 242 // UDPClientSocket, since UDPServerSocket provides Bind. |
232 DatagramSocket::BindType bind_type_; | 243 DatagramSocket::BindType bind_type_; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 SetFlowFn set_flow_func_; | 329 SetFlowFn set_flow_func_; |
319 | 330 |
320 FRIEND_TEST_ALL_PREFIXES(UDPSocketTest, SetDSCPFake); | 331 FRIEND_TEST_ALL_PREFIXES(UDPSocketTest, SetDSCPFake); |
321 DISALLOW_COPY_AND_ASSIGN(QwaveAPI); | 332 DISALLOW_COPY_AND_ASSIGN(QwaveAPI); |
322 }; | 333 }; |
323 | 334 |
324 | 335 |
325 } // namespace net | 336 } // namespace net |
326 | 337 |
327 #endif // NET_UDP_UDP_SOCKET_WIN_H_ | 338 #endif // NET_UDP_UDP_SOCKET_WIN_H_ |
OLD | NEW |