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

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

Issue 8200011: Add NetLog support to UDP sockets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: ??? Created 9 years, 2 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
« no previous file with comments | « net/udp/udp_socket_unittest.cc ('k') | net/udp/udp_socket_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <winsock2.h> 9 #include <winsock2.h>
10 10
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
14 #include "base/win/object_watcher.h" 14 #include "base/win/object_watcher.h"
15 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
16 #include "net/base/rand_callback.h" 16 #include "net/base/rand_callback.h"
17 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
18 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
19 #include "net/base/net_log.h" 19 #include "net/base/net_log.h"
20 #include "net/udp/datagram_socket.h" 20 #include "net/udp/datagram_socket.h"
21 21
22 namespace net { 22 namespace net {
23 23
24 class BoundNetLog;
25
26 class UDPSocketWin : public base::NonThreadSafe { 24 class UDPSocketWin : public base::NonThreadSafe {
27 public: 25 public:
28 UDPSocketWin(DatagramSocket::BindType bind_type, 26 UDPSocketWin(DatagramSocket::BindType bind_type,
29 const RandIntCallback& rand_int_cb, 27 const RandIntCallback& rand_int_cb,
30 net::NetLog* net_log, 28 net::NetLog* net_log,
31 const net::NetLog::Source& source); 29 const net::NetLog::Source& source);
32 virtual ~UDPSocketWin(); 30 virtual ~UDPSocketWin();
33 31
34 // Connect the socket to connect with a certain |address|. 32 // Connect the socket to connect with a certain |address|.
35 // Returns a net error code. 33 // Returns a net error code.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 virtual void OnObjectSignaled(HANDLE object); 127 virtual void OnObjectSignaled(HANDLE object);
130 128
131 private: 129 private:
132 UDPSocketWin* const socket_; 130 UDPSocketWin* const socket_;
133 }; 131 };
134 132
135 void DoReadCallback(int rv); 133 void DoReadCallback(int rv);
136 void DoWriteCallback(int rv); 134 void DoWriteCallback(int rv);
137 void DidCompleteRead(); 135 void DidCompleteRead();
138 void DidCompleteWrite(); 136 void DidCompleteWrite();
139 bool ProcessSuccessfulRead(int num_bytes, IPEndPoint* address); 137
140 void ProcessSuccessfulWrite(int num_bytes); 138 // Handles stats and logging. |result| is the number of bytes transferred, on
139 // success, or the net error code on failure. LogRead retrieves the address
140 // from |recv_addr_storage_|, while LogWrite takes it as an optional argument.
141 void LogRead(int result, const char* bytes) const;
142 void LogWrite(int result, const char* bytes, const IPEndPoint* address) const;
141 143
142 // Returns the OS error code (or 0 on success). 144 // Returns the OS error code (or 0 on success).
143 int CreateSocket(const IPEndPoint& address); 145 int CreateSocket(const IPEndPoint& address);
144 146
145 // Same as SendTo(), except that address is passed by pointer 147 // Same as SendTo(), except that address is passed by pointer
146 // instead of by reference. It is called from Write() with |address| 148 // instead of by reference. It is called from Write() with |address|
147 // set to NULL. 149 // set to NULL.
148 int SendToOrWrite(IOBuffer* buf, 150 int SendToOrWrite(IOBuffer* buf,
149 int buf_len, 151 int buf_len,
150 const IPEndPoint* address, 152 const IPEndPoint* address,
151 OldCompletionCallback* callback); 153 OldCompletionCallback* callback);
152 154
155 int InternalConnect(const IPEndPoint& address);
153 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); 156 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address);
154 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); 157 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address);
155 158
156 int DoBind(const IPEndPoint& address); 159 int DoBind(const IPEndPoint& address);
157 int RandomBind(const IPEndPoint& address); 160 int RandomBind(const IPEndPoint& address);
158 161
162 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_|
163 // to an IPEndPoint and writes it to |address|. Returns true on success.
164 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const;
165
159 SOCKET socket_; 166 SOCKET socket_;
160 167
161 // How to do source port binding, used only when UDPSocket is part of 168 // How to do source port binding, used only when UDPSocket is part of
162 // UDPClientSocket, since UDPServerSocket provides Bind. 169 // UDPClientSocket, since UDPServerSocket provides Bind.
163 DatagramSocket::BindType bind_type_; 170 DatagramSocket::BindType bind_type_;
164 171
165 // PRNG function for generating port numbers. 172 // PRNG function for generating port numbers.
166 RandIntCallback rand_int_cb_; 173 RandIntCallback rand_int_cb_;
167 174
168 // These are mutable since they're just cached copies to make 175 // These are mutable since they're just cached copies to make
(...skipping 12 matching lines...) Expand all
181 // OVERLAPPED for pending read and write operations. 188 // OVERLAPPED for pending read and write operations.
182 OVERLAPPED read_overlapped_; 189 OVERLAPPED read_overlapped_;
183 OVERLAPPED write_overlapped_; 190 OVERLAPPED write_overlapped_;
184 191
185 // The buffer used by InternalRead() to retry Read requests 192 // The buffer used by InternalRead() to retry Read requests
186 scoped_refptr<IOBuffer> read_iobuffer_; 193 scoped_refptr<IOBuffer> read_iobuffer_;
187 struct sockaddr_storage recv_addr_storage_; 194 struct sockaddr_storage recv_addr_storage_;
188 socklen_t recv_addr_len_; 195 socklen_t recv_addr_len_;
189 IPEndPoint* recv_from_address_; 196 IPEndPoint* recv_from_address_;
190 197
198 // Cached copy of the current address we're sending to, if any. Used for
199 // logging.
200 scoped_ptr<IPEndPoint> send_to_address_;
201
191 // The buffer used by InternalWrite() to retry Write requests 202 // The buffer used by InternalWrite() to retry Write requests
192 scoped_refptr<IOBuffer> write_iobuffer_; 203 scoped_refptr<IOBuffer> write_iobuffer_;
193 204
194 // External callback; called when read is complete. 205 // External callback; called when read is complete.
195 OldCompletionCallback* read_callback_; 206 OldCompletionCallback* read_callback_;
196 207
197 // External callback; called when write is complete. 208 // External callback; called when write is complete.
198 OldCompletionCallback* write_callback_; 209 OldCompletionCallback* write_callback_;
199 210
200 BoundNetLog net_log_; 211 BoundNetLog net_log_;
201 212
202 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); 213 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin);
203 }; 214 };
204 215
205 } // namespace net 216 } // namespace net
206 217
207 #endif // NET_UDP_UDP_SOCKET_WIN_H_ 218 #endif // NET_UDP_UDP_SOCKET_WIN_H_
OLDNEW
« no previous file with comments | « net/udp/udp_socket_unittest.cc ('k') | net/udp/udp_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698