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_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 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 private: | 77 private: |
78 // State machine for connecting the socket. | 78 // State machine for connecting the socket. |
79 enum ConnectState { | 79 enum ConnectState { |
80 CONNECT_STATE_CONNECT, | 80 CONNECT_STATE_CONNECT, |
81 CONNECT_STATE_CONNECT_COMPLETE, | 81 CONNECT_STATE_CONNECT_COMPLETE, |
82 CONNECT_STATE_NONE, | 82 CONNECT_STATE_NONE, |
83 }; | 83 }; |
84 | 84 |
85 class ReadWatcher : public MessageLoopForIO::Watcher { | 85 class ReadWatcher : public MessageLoopForIO::Watcher { |
86 public: | 86 public: |
87 explicit ReadWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} | 87 explicit ReadWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} |
mmenke
2012/08/09 15:13:35
Sholdn't this also be de-inlined?
hans
2012/08/09 15:35:42
The plugin didn't complain about it.
| |
88 | 88 |
89 // MessageLoopForIO::Watcher methods | 89 // MessageLoopForIO::Watcher methods |
90 | 90 |
91 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { | 91 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE; |
92 if (!socket_->read_callback_.is_null()) | |
93 socket_->DidCompleteRead(); | |
94 } | |
95 | 92 |
96 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {} | 93 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {} |
97 | 94 |
98 private: | 95 private: |
99 TCPClientSocketLibevent* const socket_; | 96 TCPClientSocketLibevent* const socket_; |
100 | 97 |
101 DISALLOW_COPY_AND_ASSIGN(ReadWatcher); | 98 DISALLOW_COPY_AND_ASSIGN(ReadWatcher); |
102 }; | 99 }; |
103 | 100 |
104 class WriteWatcher : public MessageLoopForIO::Watcher { | 101 class WriteWatcher : public MessageLoopForIO::Watcher { |
105 public: | 102 public: |
106 explicit WriteWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} | 103 explicit WriteWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} |
mmenke
2012/08/09 15:13:35
Sholdn't this also be de-inlined?
hans
2012/08/09 15:35:42
The plugin didn't complain about it.
| |
107 | 104 |
108 // MessageLoopForIO::Watcher implementation. | 105 // MessageLoopForIO::Watcher implementation. |
109 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {} | 106 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {} |
110 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { | 107 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE; |
111 if (socket_->waiting_connect()) { | |
112 socket_->DidCompleteConnect(); | |
113 } else if (!socket_->write_callback_.is_null()) { | |
114 socket_->DidCompleteWrite(); | |
115 } | |
116 } | |
117 | 108 |
118 private: | 109 private: |
119 TCPClientSocketLibevent* const socket_; | 110 TCPClientSocketLibevent* const socket_; |
120 | 111 |
121 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); | 112 DISALLOW_COPY_AND_ASSIGN(WriteWatcher); |
122 }; | 113 }; |
123 | 114 |
124 // State machine used by Connect(). | 115 // State machine used by Connect(). |
125 int DoConnectLoop(int result); | 116 int DoConnectLoop(int result); |
126 int DoConnect(); | 117 int DoConnect(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 base::TimeTicks connect_start_time_; | 199 base::TimeTicks connect_start_time_; |
209 base::TimeDelta connect_time_micros_; | 200 base::TimeDelta connect_time_micros_; |
210 int64 num_bytes_read_; | 201 int64 num_bytes_read_; |
211 | 202 |
212 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent); | 203 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent); |
213 }; | 204 }; |
214 | 205 |
215 } // namespace net | 206 } // namespace net |
216 | 207 |
217 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ | 208 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ |
OLD | NEW |