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

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

Issue 8801004: base::Bind: Convert StreamSocket::Connect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes Created 9 years 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
« no previous file with comments | « net/socket/stream_socket.h ('k') | net/socket/tcp_client_socket_libevent.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 (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 24 matching lines...) Expand all
35 // AdoptSocket causes the given, connected socket to be adopted as a TCP 35 // AdoptSocket causes the given, connected socket to be adopted as a TCP
36 // socket. This object must not be connected. This object takes ownership of 36 // socket. This object must not be connected. This object takes ownership of
37 // the given socket and then acts as if Connect() had been called. This 37 // the given socket and then acts as if Connect() had been called. This
38 // function is used by TCPServerSocket() to adopt accepted connections 38 // function is used by TCPServerSocket() to adopt accepted connections
39 // and for testing. 39 // and for testing.
40 int AdoptSocket(int socket); 40 int AdoptSocket(int socket);
41 41
42 // Binds the socket to a local IP address and port. 42 // Binds the socket to a local IP address and port.
43 int Bind(const IPEndPoint& address); 43 int Bind(const IPEndPoint& address);
44 44
45 // StreamSocket methods: 45 // StreamSocket implementation.
46 virtual int Connect(OldCompletionCallback* callback) OVERRIDE; 46 virtual int Connect(OldCompletionCallback* callback) OVERRIDE;
47 virtual int Connect(const CompletionCallback& callback) OVERRIDE;
47 virtual void Disconnect() OVERRIDE; 48 virtual void Disconnect() OVERRIDE;
48 virtual bool IsConnected() const OVERRIDE; 49 virtual bool IsConnected() const OVERRIDE;
49 virtual bool IsConnectedAndIdle() const OVERRIDE; 50 virtual bool IsConnectedAndIdle() const OVERRIDE;
50 virtual int GetPeerAddress(AddressList* address) const OVERRIDE; 51 virtual int GetPeerAddress(AddressList* address) const OVERRIDE;
51 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 52 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
52 virtual const BoundNetLog& NetLog() const OVERRIDE; 53 virtual const BoundNetLog& NetLog() const OVERRIDE;
53 virtual void SetSubresourceSpeculation() OVERRIDE; 54 virtual void SetSubresourceSpeculation() OVERRIDE;
54 virtual void SetOmniboxSpeculation() OVERRIDE; 55 virtual void SetOmniboxSpeculation() OVERRIDE;
55 virtual bool WasEverUsed() const OVERRIDE; 56 virtual bool WasEverUsed() const OVERRIDE;
56 virtual bool UsingTCPFastOpen() const OVERRIDE; 57 virtual bool UsingTCPFastOpen() const OVERRIDE;
57 virtual int64 NumBytesRead() const OVERRIDE; 58 virtual int64 NumBytesRead() const OVERRIDE;
58 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; 59 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
59 60
60 // Socket methods: 61 // Socket implementation.
61 // Multiple outstanding requests are not supported. 62 // Multiple outstanding requests are not supported.
62 // 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
63 virtual int Read(IOBuffer* buf, 64 virtual int Read(IOBuffer* buf,
64 int buf_len, 65 int buf_len,
65 OldCompletionCallback* callback) OVERRIDE; 66 OldCompletionCallback* callback) OVERRIDE;
66 virtual int Write(IOBuffer* buf, 67 virtual int Write(IOBuffer* buf,
67 int buf_len, 68 int buf_len,
68 OldCompletionCallback* callback) OVERRIDE; 69 OldCompletionCallback* callback) OVERRIDE;
69 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; 70 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
70 virtual bool SetSendBufferSize(int32 size) OVERRIDE; 71 virtual bool SetSendBufferSize(int32 size) OVERRIDE;
(...skipping 22 matching lines...) Expand all
93 private: 94 private:
94 TCPClientSocketLibevent* const socket_; 95 TCPClientSocketLibevent* const socket_;
95 96
96 DISALLOW_COPY_AND_ASSIGN(ReadWatcher); 97 DISALLOW_COPY_AND_ASSIGN(ReadWatcher);
97 }; 98 };
98 99
99 class WriteWatcher : public MessageLoopForIO::Watcher { 100 class WriteWatcher : public MessageLoopForIO::Watcher {
100 public: 101 public:
101 explicit WriteWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} 102 explicit WriteWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {}
102 103
103 // MessageLoopForIO::Watcher methods 104 // MessageLoopForIO::Watcher implementation.
104
105 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {} 105 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {}
106
107 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { 106 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {
108 if (socket_->waiting_connect()) { 107 if (socket_->waiting_connect()) {
109 socket_->DidCompleteConnect(); 108 socket_->DidCompleteConnect();
110 } else if (socket_->write_callback_) { 109 } else if (socket_->old_write_callback_ ||
110 !socket_->write_callback_.is_null()) {
111 socket_->DidCompleteWrite(); 111 socket_->DidCompleteWrite();
112 } 112 }
113 } 113 }
114 114
115 private: 115 private:
116 TCPClientSocketLibevent* const socket_; 116 TCPClientSocketLibevent* const socket_;
117 117
118 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); 118 DISALLOW_COPY_AND_ASSIGN(WriteWatcher);
119 }; 119 };
120 120
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 int read_buf_len_; 172 int read_buf_len_;
173 173
174 // The buffer used by OnSocketReady to retry Write requests 174 // The buffer used by OnSocketReady to retry Write requests
175 scoped_refptr<IOBuffer> write_buf_; 175 scoped_refptr<IOBuffer> write_buf_;
176 int write_buf_len_; 176 int write_buf_len_;
177 177
178 // External callback; called when read is complete. 178 // External callback; called when read is complete.
179 OldCompletionCallback* read_callback_; 179 OldCompletionCallback* read_callback_;
180 180
181 // External callback; called when write is complete. 181 // External callback; called when write is complete.
182 OldCompletionCallback* write_callback_; 182 OldCompletionCallback* old_write_callback_;
183 CompletionCallback write_callback_;
183 184
184 // The next state for the Connect() state machine. 185 // The next state for the Connect() state machine.
185 ConnectState next_connect_state_; 186 ConnectState next_connect_state_;
186 187
187 // The OS error that CONNECT_STATE_CONNECT last completed with. 188 // The OS error that CONNECT_STATE_CONNECT last completed with.
188 int connect_os_error_; 189 int connect_os_error_;
189 190
190 BoundNetLog net_log_; 191 BoundNetLog net_log_;
191 192
192 // This socket was previously disconnected and has not been re-connected. 193 // This socket was previously disconnected and has not been re-connected.
(...skipping 12 matching lines...) Expand all
205 base::TimeTicks connect_start_time_; 206 base::TimeTicks connect_start_time_;
206 base::TimeDelta connect_time_micros_; 207 base::TimeDelta connect_time_micros_;
207 int64 num_bytes_read_; 208 int64 num_bytes_read_;
208 209
209 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent); 210 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent);
210 }; 211 };
211 212
212 } // namespace net 213 } // namespace net
213 214
214 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ 215 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_
OLDNEW
« no previous file with comments | « net/socket/stream_socket.h ('k') | net/socket/tcp_client_socket_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698