OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CLIENT_SOCKET_WIN_H_ | 5 #ifndef NET_SOCKET_TCP_CLIENT_SOCKET_WIN_H_ |
6 #define NET_SOCKET_TCP_CLIENT_SOCKET_WIN_H_ | 6 #define NET_SOCKET_TCP_CLIENT_SOCKET_WIN_H_ |
7 | 7 |
8 #include <winsock2.h> | 8 #include <winsock2.h> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const CompletionCallback& callback); | 65 const CompletionCallback& callback); |
66 virtual int Write(IOBuffer* buf, int buf_len, | 66 virtual int Write(IOBuffer* buf, int buf_len, |
67 const CompletionCallback& callback); | 67 const CompletionCallback& callback); |
68 | 68 |
69 virtual bool SetReceiveBufferSize(int32 size); | 69 virtual bool SetReceiveBufferSize(int32 size); |
70 virtual bool SetSendBufferSize(int32 size); | 70 virtual bool SetSendBufferSize(int32 size); |
71 | 71 |
72 virtual bool SetKeepAlive(bool enable, int delay); | 72 virtual bool SetKeepAlive(bool enable, int delay); |
73 virtual bool SetNoDelay(bool no_delay); | 73 virtual bool SetNoDelay(bool no_delay); |
74 | 74 |
| 75 // Perform reads in non-blocking mode instead of overlapped mode. |
| 76 // Used for experiments. |
| 77 static void DisableOverlappedReads(); |
| 78 |
75 private: | 79 private: |
76 // State machine for connecting the socket. | 80 // State machine for connecting the socket. |
77 enum ConnectState { | 81 enum ConnectState { |
78 CONNECT_STATE_CONNECT, | 82 CONNECT_STATE_CONNECT, |
79 CONNECT_STATE_CONNECT_COMPLETE, | 83 CONNECT_STATE_CONNECT_COMPLETE, |
80 CONNECT_STATE_NONE, | 84 CONNECT_STATE_NONE, |
81 }; | 85 }; |
82 | 86 |
83 class Core; | 87 class Core; |
84 | 88 |
85 // State machine used by Connect(). | 89 // State machine used by Connect(). |
86 int DoConnectLoop(int result); | 90 int DoConnectLoop(int result); |
87 int DoConnect(); | 91 int DoConnect(); |
88 int DoConnectComplete(int result); | 92 int DoConnectComplete(int result); |
89 | 93 |
90 // Helper used by Disconnect(), which disconnects minus the logging and | 94 // Helper used by Disconnect(), which disconnects minus the logging and |
91 // resetting of current_address_index_. | 95 // resetting of current_address_index_. |
92 void DoDisconnect(); | 96 void DoDisconnect(); |
93 | 97 |
94 // Returns true if a Connect() is in progress. | 98 // Returns true if a Connect() is in progress. |
95 bool waiting_connect() const { | 99 bool waiting_connect() const { |
96 return next_connect_state_ != CONNECT_STATE_NONE; | 100 return next_connect_state_ != CONNECT_STATE_NONE; |
97 } | 101 } |
98 | 102 |
99 // Called after Connect() has completed with |net_error|. | 103 // Called after Connect() has completed with |net_error|. |
100 void LogConnectCompletion(int net_error); | 104 void LogConnectCompletion(int net_error); |
101 | 105 |
| 106 int DoRead(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
102 void DoReadCallback(int rv); | 107 void DoReadCallback(int rv); |
103 void DoWriteCallback(int rv); | 108 void DoWriteCallback(int rv); |
104 void DidCompleteConnect(); | 109 void DidCompleteConnect(); |
105 void DidCompleteRead(); | 110 void DidCompleteRead(); |
106 void DidCompleteWrite(); | 111 void DidCompleteWrite(); |
| 112 void DidSignalRead(); |
107 | 113 |
108 SOCKET socket_; | 114 SOCKET socket_; |
109 | 115 |
110 // Local IP address and port we are bound to. Set to NULL if Bind() | 116 // Local IP address and port we are bound to. Set to NULL if Bind() |
111 // was't called (in that cases OS chooses address/port). | 117 // was't called (in that cases OS chooses address/port). |
112 scoped_ptr<IPEndPoint> bind_address_; | 118 scoped_ptr<IPEndPoint> bind_address_; |
113 | 119 |
114 // Stores bound socket between Bind() and Connect() calls. | 120 // Stores bound socket between Bind() and Connect() calls. |
115 SOCKET bound_socket_; | 121 SOCKET bound_socket_; |
116 | 122 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 base::TimeTicks connect_start_time_; | 159 base::TimeTicks connect_start_time_; |
154 base::TimeDelta connect_time_micros_; | 160 base::TimeDelta connect_time_micros_; |
155 int64 num_bytes_read_; | 161 int64 num_bytes_read_; |
156 | 162 |
157 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketWin); | 163 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketWin); |
158 }; | 164 }; |
159 | 165 |
160 } // namespace net | 166 } // namespace net |
161 | 167 |
162 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_WIN_H_ | 168 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_WIN_H_ |
OLD | NEW |