OLD | NEW |
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_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ | 5 #ifndef NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ |
6 #define NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ | 6 #define NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 virtual bool UsingTCPFastOpen() const OVERRIDE; | 57 virtual bool UsingTCPFastOpen() const OVERRIDE; |
58 virtual int64 NumBytesRead() const OVERRIDE; | 58 virtual int64 NumBytesRead() const OVERRIDE; |
59 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; | 59 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
60 | 60 |
61 // Socket implementation. | 61 // Socket implementation. |
62 // Multiple outstanding requests are not supported. | 62 // Multiple outstanding requests are not supported. |
63 // Full duplex mode (reading and writing at the same time) is supported | 63 // Full duplex mode (reading and writing at the same time) is supported |
64 virtual int Read(IOBuffer* buf, | 64 virtual int Read(IOBuffer* buf, |
65 int buf_len, | 65 int buf_len, |
66 OldCompletionCallback* callback) OVERRIDE; | 66 OldCompletionCallback* callback) OVERRIDE; |
| 67 virtual int Read(IOBuffer* buf, |
| 68 int buf_len, |
| 69 const CompletionCallback& callback) OVERRIDE; |
67 virtual int Write(IOBuffer* buf, | 70 virtual int Write(IOBuffer* buf, |
68 int buf_len, | 71 int buf_len, |
69 OldCompletionCallback* callback) OVERRIDE; | 72 OldCompletionCallback* callback) OVERRIDE; |
70 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; | 73 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
71 virtual bool SetSendBufferSize(int32 size) OVERRIDE; | 74 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
72 | 75 |
73 private: | 76 private: |
74 // State machine for connecting the socket. | 77 // State machine for connecting the socket. |
75 enum ConnectState { | 78 enum ConnectState { |
76 CONNECT_STATE_CONNECT, | 79 CONNECT_STATE_CONNECT, |
77 CONNECT_STATE_CONNECT_COMPLETE, | 80 CONNECT_STATE_CONNECT_COMPLETE, |
78 CONNECT_STATE_NONE, | 81 CONNECT_STATE_NONE, |
79 }; | 82 }; |
80 | 83 |
81 class ReadWatcher : public MessageLoopForIO::Watcher { | 84 class ReadWatcher : public MessageLoopForIO::Watcher { |
82 public: | 85 public: |
83 explicit ReadWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} | 86 explicit ReadWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} |
84 | 87 |
85 // MessageLoopForIO::Watcher methods | 88 // MessageLoopForIO::Watcher methods |
86 | 89 |
87 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { | 90 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { |
88 if (socket_->read_callback_) | 91 if (socket_->old_read_callback_) |
89 socket_->DidCompleteRead(); | 92 socket_->DidCompleteRead(); |
90 } | 93 } |
91 | 94 |
92 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {} | 95 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {} |
93 | 96 |
94 private: | 97 private: |
95 TCPClientSocketLibevent* const socket_; | 98 TCPClientSocketLibevent* const socket_; |
96 | 99 |
97 DISALLOW_COPY_AND_ASSIGN(ReadWatcher); | 100 DISALLOW_COPY_AND_ASSIGN(ReadWatcher); |
98 }; | 101 }; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 173 |
171 // The buffer used by OnSocketReady to retry Read requests | 174 // The buffer used by OnSocketReady to retry Read requests |
172 scoped_refptr<IOBuffer> read_buf_; | 175 scoped_refptr<IOBuffer> read_buf_; |
173 int read_buf_len_; | 176 int read_buf_len_; |
174 | 177 |
175 // The buffer used by OnSocketReady to retry Write requests | 178 // The buffer used by OnSocketReady to retry Write requests |
176 scoped_refptr<IOBuffer> write_buf_; | 179 scoped_refptr<IOBuffer> write_buf_; |
177 int write_buf_len_; | 180 int write_buf_len_; |
178 | 181 |
179 // External callback; called when read is complete. | 182 // External callback; called when read is complete. |
180 OldCompletionCallback* read_callback_; | 183 OldCompletionCallback* old_read_callback_; |
| 184 CompletionCallback read_callback_; |
181 | 185 |
182 // External callback; called when write is complete. | 186 // External callback; called when write is complete. |
183 OldCompletionCallback* old_write_callback_; | 187 OldCompletionCallback* old_write_callback_; |
184 CompletionCallback write_callback_; | 188 CompletionCallback write_callback_; |
185 | 189 |
186 // The next state for the Connect() state machine. | 190 // The next state for the Connect() state machine. |
187 ConnectState next_connect_state_; | 191 ConnectState next_connect_state_; |
188 | 192 |
189 // The OS error that CONNECT_STATE_CONNECT last completed with. | 193 // The OS error that CONNECT_STATE_CONNECT last completed with. |
190 int connect_os_error_; | 194 int connect_os_error_; |
(...skipping 16 matching lines...) Expand all Loading... |
207 base::TimeTicks connect_start_time_; | 211 base::TimeTicks connect_start_time_; |
208 base::TimeDelta connect_time_micros_; | 212 base::TimeDelta connect_time_micros_; |
209 int64 num_bytes_read_; | 213 int64 num_bytes_read_; |
210 | 214 |
211 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent); | 215 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent); |
212 }; | 216 }; |
213 | 217 |
214 } // namespace net | 218 } // namespace net |
215 | 219 |
216 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ | 220 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ |
OLD | NEW |