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

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

Issue 10918158: [net/udp] Create UDPSocketWin::Core which persists until all network operations complete. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
« no previous file with comments | « no previous file | net/udp/udp_socket_win.cc » ('j') | net/udp/udp_socket_win.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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_; 185 struct sockaddr_storage recv_addr_storage_;
217 socklen_t recv_addr_len_; 186 socklen_t recv_addr_len_;
wtc 2012/09/12 01:40:29 BUG: recv_addr_storage_ and recv_addr_len_ need to
218 IPEndPoint* recv_from_address_; 187 IPEndPoint* recv_from_address_;
219 188
220 // Cached copy of the current address we're sending to, if any. Used for 189 // Cached copy of the current address we're sending to, if any. Used for
221 // logging. 190 // logging.
222 scoped_ptr<IPEndPoint> send_to_address_; 191 scoped_ptr<IPEndPoint> send_to_address_;
223 192
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. 193 // External callback; called when read is complete.
228 CompletionCallback read_callback_; 194 CompletionCallback read_callback_;
229 195
230 // External callback; called when write is complete. 196 // External callback; called when write is complete.
231 CompletionCallback write_callback_; 197 CompletionCallback write_callback_;
232 198
233 BoundNetLog net_log_; 199 BoundNetLog net_log_;
234 200
235 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); 201 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin);
236 }; 202 };
237 203
238 } // namespace net 204 } // namespace net
239 205
240 #endif // NET_UDP_UDP_SOCKET_WIN_H_ 206 #endif // NET_UDP_UDP_SOCKET_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | net/udp/udp_socket_win.cc » ('j') | net/udp/udp_socket_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698