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

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: Don't do address conversions on windows when we don't have to. 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. Also, if |address| is non-NULL, attempts
133 // to populate it using data from |recv_addr_storage_|. Returns false if
134 // unable to convert |recv_addr_storage_| to an IPEndPoint.
135 bool ProcessSuccessfulRead(int num_bytes, const char* bytes,
136 IPEndPoint* address) const;
137 // Handles stats and logging.
138 void ProcessSuccessfulWrite(int num_bytes, const char* bytes,
139 const IPEndPoint* address) const;
135 140
136 // Returns the OS error code (or 0 on success). 141 // Returns the OS error code (or 0 on success).
137 int CreateSocket(const IPEndPoint& address); 142 int CreateSocket(const IPEndPoint& address);
138 143
139 // Same as SendTo(), except that address is passed by pointer 144 // Same as SendTo(), except that address is passed by pointer
140 // instead of by reference. It is called from Write() with |address| 145 // instead of by reference. It is called from Write() with |address|
141 // set to NULL. 146 // set to NULL.
142 int SendToOrWrite(IOBuffer* buf, 147 int SendToOrWrite(IOBuffer* buf,
143 int buf_len, 148 int buf_len,
144 const IPEndPoint* address, 149 const IPEndPoint* address,
145 OldCompletionCallback* callback); 150 OldCompletionCallback* callback);
146 151
152 int InternalConnect(const IPEndPoint& address);
147 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); 153 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address);
148 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); 154 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address);
149 155
150 int DoBind(const IPEndPoint& address); 156 int DoBind(const IPEndPoint& address);
151 int RandomBind(const IPEndPoint& address); 157 int RandomBind(const IPEndPoint& address);
152 158
153 SOCKET socket_; 159 SOCKET socket_;
154 160
155 // How to do source port binding, used only when UDPSocket is part of 161 // How to do source port binding, used only when UDPSocket is part of
156 // UDPClientSocket, since UDPServerSocket provides Bind. 162 // UDPClientSocket, since UDPServerSocket provides Bind.
(...skipping 18 matching lines...) Expand all
175 // OVERLAPPED for pending read and write operations. 181 // OVERLAPPED for pending read and write operations.
176 OVERLAPPED read_overlapped_; 182 OVERLAPPED read_overlapped_;
177 OVERLAPPED write_overlapped_; 183 OVERLAPPED write_overlapped_;
178 184
179 // The buffer used by InternalRead() to retry Read requests 185 // The buffer used by InternalRead() to retry Read requests
180 scoped_refptr<IOBuffer> read_iobuffer_; 186 scoped_refptr<IOBuffer> read_iobuffer_;
181 struct sockaddr_storage recv_addr_storage_; 187 struct sockaddr_storage recv_addr_storage_;
182 socklen_t recv_addr_len_; 188 socklen_t recv_addr_len_;
183 IPEndPoint* recv_from_address_; 189 IPEndPoint* recv_from_address_;
184 190
191 // Cached copy of the current address we're sending to, if any. Used for
192 // logging.
193 scoped_ptr<IPEndPoint> send_to_address_;
Sergey Ulanov 2011/10/14 20:15:47 Does this need to be a pointer? Can we store it by
mmenke 2011/10/17 17:35:20 It can be null, and there's no IPEndPoint::IsValid
194
185 // The buffer used by InternalWrite() to retry Write requests 195 // The buffer used by InternalWrite() to retry Write requests
186 scoped_refptr<IOBuffer> write_iobuffer_; 196 scoped_refptr<IOBuffer> write_iobuffer_;
187 197
188 // External callback; called when read is complete. 198 // External callback; called when read is complete.
189 OldCompletionCallback* read_callback_; 199 OldCompletionCallback* read_callback_;
190 200
191 // External callback; called when write is complete. 201 // External callback; called when write is complete.
192 OldCompletionCallback* write_callback_; 202 OldCompletionCallback* write_callback_;
193 203
194 BoundNetLog net_log_; 204 BoundNetLog net_log_;
195 205
196 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); 206 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin);
197 }; 207 };
198 208
199 } // namespace net 209 } // namespace net
200 210
201 #endif // NET_UDP_UDP_SOCKET_WIN_H_ 211 #endif // NET_UDP_UDP_SOCKET_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698