| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 private: | 118 private: |
| 119 enum SocketOptions { | 119 enum SocketOptions { |
| 120 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, | 120 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, |
| 121 SOCKET_OPTION_BROADCAST = 1 << 1 | 121 SOCKET_OPTION_BROADCAST = 1 << 1 |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 class ReadDelegate : public base::win::ObjectWatcher::Delegate { | 124 class Core; |
| 125 public: | |
| 126 explicit ReadDelegate(UDPSocketWin* socket) : socket_(socket) {} | |
| 127 virtual ~ReadDelegate() {} | |
| 128 | |
| 129 // base::ObjectWatcher::Delegate methods: | |
| 130 virtual void OnObjectSignaled(HANDLE object); | |
| 131 | |
| 132 private: | |
| 133 UDPSocketWin* const socket_; | |
| 134 }; | |
| 135 | |
| 136 class WriteDelegate : public base::win::ObjectWatcher::Delegate { | |
| 137 public: | |
| 138 explicit WriteDelegate(UDPSocketWin* socket) : socket_(socket) {} | |
| 139 virtual ~WriteDelegate() {} | |
| 140 | |
| 141 // base::ObjectWatcher::Delegate methods: | |
| 142 virtual void OnObjectSignaled(HANDLE object); | |
| 143 | |
| 144 private: | |
| 145 UDPSocketWin* const socket_; | |
| 146 }; | |
| 147 | 125 |
| 148 void DoReadCallback(int rv); | 126 void DoReadCallback(int rv); |
| 149 void DoWriteCallback(int rv); | 127 void DoWriteCallback(int rv); |
| 150 void DidCompleteRead(); | 128 void DidCompleteRead(); |
| 151 void DidCompleteWrite(); | 129 void DidCompleteWrite(); |
| 152 | 130 |
| 153 // Handles stats and logging. |result| is the number of bytes transferred, on | 131 // Handles stats and logging. |result| is the number of bytes transferred, on |
| 154 // success, or the net error code on failure. LogRead retrieves the address | 132 // success, or the net error code on failure. LogRead retrieves the address |
| 155 // from |recv_addr_storage_|, while LogWrite takes it as an optional argument. | 133 // from |recv_addr_storage_|, while LogWrite takes it as an optional argument. |
| 156 void LogRead(int result, const char* bytes) const; | 134 void LogRead(int result, const char* bytes) const; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 DatagramSocket::BindType bind_type_; | 170 DatagramSocket::BindType bind_type_; |
| 193 | 171 |
| 194 // PRNG function for generating port numbers. | 172 // PRNG function for generating port numbers. |
| 195 RandIntCallback rand_int_cb_; | 173 RandIntCallback rand_int_cb_; |
| 196 | 174 |
| 197 // These are mutable since they're just cached copies to make | 175 // These are mutable since they're just cached copies to make |
| 198 // GetPeerAddress/GetLocalAddress smarter. | 176 // GetPeerAddress/GetLocalAddress smarter. |
| 199 mutable scoped_ptr<IPEndPoint> local_address_; | 177 mutable scoped_ptr<IPEndPoint> local_address_; |
| 200 mutable scoped_ptr<IPEndPoint> remote_address_; | 178 mutable scoped_ptr<IPEndPoint> remote_address_; |
| 201 | 179 |
| 202 // The socket's win wrappers | 180 // The core of the socket that can live longer than the socket itself. We pass |
| 203 ReadDelegate read_delegate_; | 181 // resources to the Windows async IO functions and we have to make sure that |
| 204 WriteDelegate write_delegate_; | 182 // they are not destroyed while the OS still references them. |
| 183 scoped_refptr<Core> core_; |
| 205 | 184 |
| 206 // Watchers to watch for events from Read() and Write(). | |
| 207 base::win::ObjectWatcher read_watcher_; | |
| 208 base::win::ObjectWatcher write_watcher_; | |
| 209 | |
| 210 // OVERLAPPED for pending read and write operations. | |
| 211 OVERLAPPED read_overlapped_; | |
| 212 OVERLAPPED write_overlapped_; | |
| 213 | |
| 214 // The buffer used by InternalRead() to retry Read requests | |
| 215 scoped_refptr<IOBuffer> read_iobuffer_; | |
| 216 struct sockaddr_storage recv_addr_storage_; | |
| 217 socklen_t recv_addr_len_; | |
| 218 IPEndPoint* recv_from_address_; | 185 IPEndPoint* recv_from_address_; |
| 219 | 186 |
| 220 // Cached copy of the current address we're sending to, if any. Used for | 187 // Cached copy of the current address we're sending to, if any. Used for |
| 221 // logging. | 188 // logging. |
| 222 scoped_ptr<IPEndPoint> send_to_address_; | 189 scoped_ptr<IPEndPoint> send_to_address_; |
| 223 | 190 |
| 224 // The buffer used by InternalWrite() to retry Write requests | |
| 225 scoped_refptr<IOBuffer> write_iobuffer_; | |
| 226 | |
| 227 // External callback; called when read is complete. | 191 // External callback; called when read is complete. |
| 228 CompletionCallback read_callback_; | 192 CompletionCallback read_callback_; |
| 229 | 193 |
| 230 // External callback; called when write is complete. | 194 // External callback; called when write is complete. |
| 231 CompletionCallback write_callback_; | 195 CompletionCallback write_callback_; |
| 232 | 196 |
| 233 BoundNetLog net_log_; | 197 BoundNetLog net_log_; |
| 234 | 198 |
| 235 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); | 199 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); |
| 236 }; | 200 }; |
| 237 | 201 |
| 238 } // namespace net | 202 } // namespace net |
| 239 | 203 |
| 240 #endif // NET_UDP_UDP_SOCKET_WIN_H_ | 204 #endif // NET_UDP_UDP_SOCKET_WIN_H_ |
| OLD | NEW |