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

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
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 virtual void OnObjectSignaled(HANDLE object); 121 virtual void OnObjectSignaled(HANDLE object);
124 122
125 private: 123 private:
126 UDPSocketWin* const socket_; 124 UDPSocketWin* const socket_;
127 }; 125 };
128 126
129 void DoReadCallback(int rv); 127 void DoReadCallback(int rv);
130 void DoWriteCallback(int rv); 128 void DoWriteCallback(int rv);
131 void DidCompleteRead(); 129 void DidCompleteRead();
132 void DidCompleteWrite(); 130 void DidCompleteWrite();
133 bool ProcessSuccessfulRead(int num_bytes, IPEndPoint* address); 131
134 void ProcessSuccessfulWrite(int num_bytes); 132 // Handles stats and logging. |result| is the number of bytes transferred, on
133 // success, or the net error code on failure. Returns |result|.
134 // LogRead retrieves the address from from |recv_addr_storage_|, while
135 // LogWrite takes it as an argument.
136 int LogRead(int result, const char* bytes) const;
137 int LogWrite(int result, const char* bytes, const IPEndPoint* address) const;
135 138
136 // Returns the OS error code (or 0 on success). 139 // Returns the OS error code (or 0 on success).
137 int CreateSocket(const IPEndPoint& address); 140 int CreateSocket(const IPEndPoint& address);
138 141
139 // Same as SendTo(), except that address is passed by pointer 142 // Same as SendTo(), except that address is passed by pointer
140 // instead of by reference. It is called from Write() with |address| 143 // instead of by reference. It is called from Write() with |address|
141 // set to NULL. 144 // set to NULL.
142 int SendToOrWrite(IOBuffer* buf, 145 int SendToOrWrite(IOBuffer* buf,
143 int buf_len, 146 int buf_len,
144 const IPEndPoint* address, 147 const IPEndPoint* address,
145 OldCompletionCallback* callback); 148 OldCompletionCallback* callback);
146 149
150 int InternalConnect(const IPEndPoint& address);
147 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); 151 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address);
148 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); 152 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address);
149 153
150 int DoBind(const IPEndPoint& address); 154 int DoBind(const IPEndPoint& address);
151 int RandomBind(const IPEndPoint& address); 155 int RandomBind(const IPEndPoint& address);
152 156
157 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_|
158 // to an IPEndPoint and writes it to |address|. Returns true on success.
159 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const;
160
153 SOCKET socket_; 161 SOCKET socket_;
154 162
155 // How to do source port binding, used only when UDPSocket is part of 163 // How to do source port binding, used only when UDPSocket is part of
156 // UDPClientSocket, since UDPServerSocket provides Bind. 164 // UDPClientSocket, since UDPServerSocket provides Bind.
157 DatagramSocket::BindType bind_type_; 165 DatagramSocket::BindType bind_type_;
158 166
159 // PRNG function for generating port numbers. 167 // PRNG function for generating port numbers.
160 RandIntCallback rand_int_cb_; 168 RandIntCallback rand_int_cb_;
161 169
162 // These are mutable since they're just cached copies to make 170 // These are mutable since they're just cached copies to make
(...skipping 12 matching lines...) Expand all
175 // OVERLAPPED for pending read and write operations. 183 // OVERLAPPED for pending read and write operations.
176 OVERLAPPED read_overlapped_; 184 OVERLAPPED read_overlapped_;
177 OVERLAPPED write_overlapped_; 185 OVERLAPPED write_overlapped_;
178 186
179 // The buffer used by InternalRead() to retry Read requests 187 // The buffer used by InternalRead() to retry Read requests
180 scoped_refptr<IOBuffer> read_iobuffer_; 188 scoped_refptr<IOBuffer> read_iobuffer_;
181 struct sockaddr_storage recv_addr_storage_; 189 struct sockaddr_storage recv_addr_storage_;
182 socklen_t recv_addr_len_; 190 socklen_t recv_addr_len_;
183 IPEndPoint* recv_from_address_; 191 IPEndPoint* recv_from_address_;
184 192
193 // Cached copy of the current address we're sending to, if any. Used for
194 // logging.
195 scoped_ptr<IPEndPoint> send_to_address_;
196
185 // The buffer used by InternalWrite() to retry Write requests 197 // The buffer used by InternalWrite() to retry Write requests
186 scoped_refptr<IOBuffer> write_iobuffer_; 198 scoped_refptr<IOBuffer> write_iobuffer_;
187 199
188 // External callback; called when read is complete. 200 // External callback; called when read is complete.
189 OldCompletionCallback* read_callback_; 201 OldCompletionCallback* read_callback_;
190 202
191 // External callback; called when write is complete. 203 // External callback; called when write is complete.
192 OldCompletionCallback* write_callback_; 204 OldCompletionCallback* write_callback_;
193 205
194 BoundNetLog net_log_; 206 BoundNetLog net_log_;
195 207
196 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); 208 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin);
197 }; 209 };
198 210
199 } // namespace net 211 } // namespace net
200 212
201 #endif // NET_UDP_UDP_SOCKET_WIN_H_ 213 #endif // NET_UDP_UDP_SOCKET_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698