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

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: Fix linux yet again 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 sent, on
133 // success, or the net error code on failure. Also, on success, if |address|
134 // is non-NULL, attempts to populate it using data from |recv_addr_storage_|.
135 // Returns final result code. This will just be |result|, unless unable to
136 // convert |recv_addr_storage_| to an IPEndPoint.
137 int LogRead(int result, const char* bytes, IPEndPoint* address) const;
138 // Handles stats and logging. Values are the same as in LogRead, except
139 // |address| will not be modified. Returns |result|.
140 int LogWrite(int result, const char* bytes, const IPEndPoint* address) const;
135 141
136 // Returns the OS error code (or 0 on success). 142 // Returns the OS error code (or 0 on success).
137 int CreateSocket(const IPEndPoint& address); 143 int CreateSocket(const IPEndPoint& address);
138 144
139 // Same as SendTo(), except that address is passed by pointer 145 // Same as SendTo(), except that address is passed by pointer
140 // instead of by reference. It is called from Write() with |address| 146 // instead of by reference. It is called from Write() with |address|
141 // set to NULL. 147 // set to NULL.
142 int SendToOrWrite(IOBuffer* buf, 148 int SendToOrWrite(IOBuffer* buf,
143 int buf_len, 149 int buf_len,
144 const IPEndPoint* address, 150 const IPEndPoint* address,
145 OldCompletionCallback* callback); 151 OldCompletionCallback* callback);
146 152
153 int InternalConnect(const IPEndPoint& address);
147 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); 154 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address);
148 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); 155 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address);
149 156
150 int DoBind(const IPEndPoint& address); 157 int DoBind(const IPEndPoint& address);
151 int RandomBind(const IPEndPoint& address); 158 int RandomBind(const IPEndPoint& address);
152 159
153 SOCKET socket_; 160 SOCKET socket_;
154 161
155 // How to do source port binding, used only when UDPSocket is part of 162 // How to do source port binding, used only when UDPSocket is part of
156 // UDPClientSocket, since UDPServerSocket provides Bind. 163 // UDPClientSocket, since UDPServerSocket provides Bind.
(...skipping 18 matching lines...) Expand all
175 // OVERLAPPED for pending read and write operations. 182 // OVERLAPPED for pending read and write operations.
176 OVERLAPPED read_overlapped_; 183 OVERLAPPED read_overlapped_;
177 OVERLAPPED write_overlapped_; 184 OVERLAPPED write_overlapped_;
178 185
179 // The buffer used by InternalRead() to retry Read requests 186 // The buffer used by InternalRead() to retry Read requests
180 scoped_refptr<IOBuffer> read_iobuffer_; 187 scoped_refptr<IOBuffer> read_iobuffer_;
181 struct sockaddr_storage recv_addr_storage_; 188 struct sockaddr_storage recv_addr_storage_;
182 socklen_t recv_addr_len_; 189 socklen_t recv_addr_len_;
183 IPEndPoint* recv_from_address_; 190 IPEndPoint* recv_from_address_;
184 191
192 // Cached copy of the current address we're sending to, if any. Used for
193 // logging.
194 scoped_ptr<IPEndPoint> send_to_address_;
195
185 // The buffer used by InternalWrite() to retry Write requests 196 // The buffer used by InternalWrite() to retry Write requests
186 scoped_refptr<IOBuffer> write_iobuffer_; 197 scoped_refptr<IOBuffer> write_iobuffer_;
187 198
188 // External callback; called when read is complete. 199 // External callback; called when read is complete.
189 OldCompletionCallback* read_callback_; 200 OldCompletionCallback* read_callback_;
190 201
191 // External callback; called when write is complete. 202 // External callback; called when write is complete.
192 OldCompletionCallback* write_callback_; 203 OldCompletionCallback* write_callback_;
193 204
194 BoundNetLog net_log_; 205 BoundNetLog net_log_;
195 206
196 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); 207 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin);
197 }; 208 };
198 209
199 } // namespace net 210 } // namespace net
200 211
201 #endif // NET_UDP_UDP_SOCKET_WIN_H_ 212 #endif // NET_UDP_UDP_SOCKET_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698