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

Side by Side Diff: net/socket/tcp_socket_win.h

Issue 2815993002: Adds a method to TCPServerSocket to adopt a socket. (Closed)
Patch Set: Refined GetSocketDescriptor per review. Created 3 years, 7 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 | « net/socket/tcp_socket_unittest.cc ('k') | net/socket/tcp_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_SOCKET_TCP_SOCKET_WIN_H_ 5 #ifndef NET_SOCKET_TCP_SOCKET_WIN_H_
6 #define NET_SOCKET_TCP_SOCKET_WIN_H_ 6 #define NET_SOCKET_TCP_SOCKET_WIN_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <winsock2.h> 9 #include <winsock2.h>
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/threading/non_thread_safe.h" 16 #include "base/threading/non_thread_safe.h"
17 #include "base/win/object_watcher.h" 17 #include "base/win/object_watcher.h"
18 #include "net/base/address_family.h" 18 #include "net/base/address_family.h"
19 #include "net/base/completion_callback.h" 19 #include "net/base/completion_callback.h"
20 #include "net/base/net_export.h" 20 #include "net/base/net_export.h"
21 #include "net/log/net_log_with_source.h" 21 #include "net/log/net_log_with_source.h"
22 #include "net/socket/socket_descriptor.h"
22 #include "net/socket/socket_performance_watcher.h" 23 #include "net/socket/socket_performance_watcher.h"
23 24
24 namespace net { 25 namespace net {
25 26
26 class AddressList; 27 class AddressList;
27 class IOBuffer; 28 class IOBuffer;
28 class IPEndPoint; 29 class IPEndPoint;
29 class NetLog; 30 class NetLog;
30 struct NetLogSource; 31 struct NetLogSource;
31 32
32 class NET_EXPORT TCPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe), 33 class NET_EXPORT TCPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe),
33 public base::win::ObjectWatcher::Delegate { 34 public base::win::ObjectWatcher::Delegate {
34 public: 35 public:
35 TCPSocketWin( 36 TCPSocketWin(
36 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, 37 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
37 NetLog* net_log, 38 NetLog* net_log,
38 const NetLogSource& source); 39 const NetLogSource& source);
39 ~TCPSocketWin() override; 40 ~TCPSocketWin() override;
40 41
41 int Open(AddressFamily family); 42 int Open(AddressFamily family);
42 43
43 // Both AdoptConnectedSocket and AdoptListenSocket take ownership of an 44 // Takes ownership of |socket|, which is known to already be connected to the
44 // existing socket. AdoptConnectedSocket takes an already connected 45 // given peer address. However, peer address may be the empty address, for
45 // socket. AdoptListenSocket takes a socket that is intended to accept 46 // compatibility. The given peer address will be returned by GetPeerAddress.
46 // connection. In some sense, AdoptListenSocket is more similar to Open. 47 int AdoptConnectedSocket(SocketDescriptor socket,
47 int AdoptConnectedSocket(SOCKET socket, const IPEndPoint& peer_address); 48 const IPEndPoint& peer_address);
48 int AdoptListenSocket(SOCKET socket); 49 // Takes ownership of |socket|, which may or may not be open, bound, or
50 // listening. The caller must determine the state of the socket based on its
51 // provenance and act accordingly. The socket may have connections waiting
52 // to be accepted, but must not be actually connected.
53 int AdoptUnconnectedSocket(SocketDescriptor socket);
49 54
50 int Bind(const IPEndPoint& address); 55 int Bind(const IPEndPoint& address);
51 56
52 int Listen(int backlog); 57 int Listen(int backlog);
53 int Accept(std::unique_ptr<TCPSocketWin>* socket, 58 int Accept(std::unique_ptr<TCPSocketWin>* socket,
54 IPEndPoint* address, 59 IPEndPoint* address,
55 const CompletionCallback& callback); 60 const CompletionCallback& callback);
56 61
57 int Connect(const IPEndPoint& address, const CompletionCallback& callback); 62 int Connect(const IPEndPoint& address, const CompletionCallback& callback);
58 bool IsConnected() const; 63 bool IsConnected() const;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // NetLogEventType::TCP_CONNECT. These methods set the start/end of 113 // NetLogEventType::TCP_CONNECT. These methods set the start/end of
109 // NetLogEventType::TCP_CONNECT. 114 // NetLogEventType::TCP_CONNECT.
110 // 115 //
111 // TODO(yzshen): Change logging format and let TCPClientSocket log the 116 // TODO(yzshen): Change logging format and let TCPClientSocket log the
112 // start/end of a series of connect attempts itself. 117 // start/end of a series of connect attempts itself.
113 void StartLoggingMultipleConnectAttempts(const AddressList& addresses); 118 void StartLoggingMultipleConnectAttempts(const AddressList& addresses);
114 void EndLoggingMultipleConnectAttempts(int net_error); 119 void EndLoggingMultipleConnectAttempts(int net_error);
115 120
116 const NetLogWithSource& net_log() const { return net_log_; } 121 const NetLogWithSource& net_log() const { return net_log_; }
117 122
123 // Return the underlying SocketDescriptor and clean up this object, which may
124 // no longer be used. This method should be used only for testing. No read,
125 // write, or accept operations should be pending.
126 SocketDescriptor ReleaseSocketDescriptorForTesting();
127
118 private: 128 private:
119 class Core; 129 class Core;
120 130
121 // base::ObjectWatcher::Delegate implementation. 131 // base::ObjectWatcher::Delegate implementation.
122 void OnObjectSignaled(HANDLE object) override; 132 void OnObjectSignaled(HANDLE object) override;
123 133
124 int AcceptInternal(std::unique_ptr<TCPSocketWin>* socket, 134 int AcceptInternal(std::unique_ptr<TCPSocketWin>* socket,
125 IPEndPoint* address); 135 IPEndPoint* address);
126 136
127 int DoConnect(); 137 int DoConnect();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 bool logging_multiple_connect_attempts_; 185 bool logging_multiple_connect_attempts_;
176 186
177 NetLogWithSource net_log_; 187 NetLogWithSource net_log_;
178 188
179 DISALLOW_COPY_AND_ASSIGN(TCPSocketWin); 189 DISALLOW_COPY_AND_ASSIGN(TCPSocketWin);
180 }; 190 };
181 191
182 } // namespace net 192 } // namespace net
183 193
184 #endif // NET_SOCKET_TCP_SOCKET_WIN_H_ 194 #endif // NET_SOCKET_TCP_SOCKET_WIN_H_
OLDNEW
« no previous file with comments | « net/socket/tcp_socket_unittest.cc ('k') | net/socket/tcp_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698