| 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 25 matching lines...) Expand all Loading... |
| 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 methods: |
| 46 virtual int Connect(OldCompletionCallback* callback); | 46 virtual int Connect(OldCompletionCallback* callback) OVERRIDE; |
| 47 virtual void Disconnect(); | 47 virtual void Disconnect() OVERRIDE; |
| 48 virtual bool IsConnected() const; | 48 virtual bool IsConnected() const OVERRIDE; |
| 49 virtual bool IsConnectedAndIdle() const; | 49 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 50 virtual int GetPeerAddress(AddressList* address) const; | 50 virtual int GetPeerAddress(AddressList* address) const OVERRIDE; |
| 51 virtual int GetLocalAddress(IPEndPoint* address) const; | 51 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
| 52 virtual const BoundNetLog& NetLog() const; | 52 virtual const BoundNetLog& NetLog() const OVERRIDE; |
| 53 virtual void SetSubresourceSpeculation(); | 53 virtual void SetSubresourceSpeculation() OVERRIDE; |
| 54 virtual void SetOmniboxSpeculation(); | 54 virtual void SetOmniboxSpeculation() OVERRIDE; |
| 55 virtual bool WasEverUsed() const; | 55 virtual bool WasEverUsed() const OVERRIDE; |
| 56 virtual bool UsingTCPFastOpen() const; | 56 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 57 virtual int64 NumBytesRead() const; | 57 virtual int64 NumBytesRead() const OVERRIDE; |
| 58 virtual base::TimeDelta GetConnectTimeMicros() const; | 58 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
| 59 | 59 |
| 60 // Socket methods: | 60 // Socket methods: |
| 61 // Multiple outstanding requests are not supported. | 61 // Multiple outstanding requests are not supported. |
| 62 // Full duplex mode (reading and writing at the same time) is supported | 62 // Full duplex mode (reading and writing at the same time) is supported |
| 63 virtual int Read(IOBuffer* buf, int buf_len, OldCompletionCallback* callback); | 63 virtual int Read(IOBuffer* buf, |
| 64 virtual int Write(IOBuffer* buf, int buf_len, OldCompletionCallback* callback)
; | 64 int buf_len, |
| 65 virtual bool SetReceiveBufferSize(int32 size); | 65 OldCompletionCallback* callback) OVERRIDE; |
| 66 virtual bool SetSendBufferSize(int32 size); | 66 virtual int Write(IOBuffer* buf, |
| 67 int buf_len, |
| 68 OldCompletionCallback* callback) OVERRIDE; |
| 69 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
| 70 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
| 67 | 71 |
| 68 private: | 72 private: |
| 69 // State machine for connecting the socket. | 73 // State machine for connecting the socket. |
| 70 enum ConnectState { | 74 enum ConnectState { |
| 71 CONNECT_STATE_CONNECT, | 75 CONNECT_STATE_CONNECT, |
| 72 CONNECT_STATE_CONNECT_COMPLETE, | 76 CONNECT_STATE_CONNECT_COMPLETE, |
| 73 CONNECT_STATE_NONE, | 77 CONNECT_STATE_NONE, |
| 74 }; | 78 }; |
| 75 | 79 |
| 76 class ReadWatcher : public MessageLoopForIO::Watcher { | 80 class ReadWatcher : public MessageLoopForIO::Watcher { |
| 77 public: | 81 public: |
| 78 explicit ReadWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} | 82 explicit ReadWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} |
| 79 | 83 |
| 80 // MessageLoopForIO::Watcher methods | 84 // MessageLoopForIO::Watcher methods |
| 81 | 85 |
| 82 virtual void OnFileCanReadWithoutBlocking(int /* fd */) { | 86 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { |
| 83 if (socket_->read_callback_) | 87 if (socket_->read_callback_) |
| 84 socket_->DidCompleteRead(); | 88 socket_->DidCompleteRead(); |
| 85 } | 89 } |
| 86 | 90 |
| 87 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) {} | 91 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {} |
| 88 | 92 |
| 89 private: | 93 private: |
| 90 TCPClientSocketLibevent* const socket_; | 94 TCPClientSocketLibevent* const socket_; |
| 91 | 95 |
| 92 DISALLOW_COPY_AND_ASSIGN(ReadWatcher); | 96 DISALLOW_COPY_AND_ASSIGN(ReadWatcher); |
| 93 }; | 97 }; |
| 94 | 98 |
| 95 class WriteWatcher : public MessageLoopForIO::Watcher { | 99 class WriteWatcher : public MessageLoopForIO::Watcher { |
| 96 public: | 100 public: |
| 97 explicit WriteWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} | 101 explicit WriteWatcher(TCPClientSocketLibevent* socket) : socket_(socket) {} |
| 98 | 102 |
| 99 // MessageLoopForIO::Watcher methods | 103 // MessageLoopForIO::Watcher methods |
| 100 | 104 |
| 101 virtual void OnFileCanReadWithoutBlocking(int /* fd */) {} | 105 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE {} |
| 102 | 106 |
| 103 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) { | 107 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { |
| 104 if (socket_->waiting_connect()) { | 108 if (socket_->waiting_connect()) { |
| 105 socket_->DidCompleteConnect(); | 109 socket_->DidCompleteConnect(); |
| 106 } else if (socket_->write_callback_) { | 110 } else if (socket_->write_callback_) { |
| 107 socket_->DidCompleteWrite(); | 111 socket_->DidCompleteWrite(); |
| 108 } | 112 } |
| 109 } | 113 } |
| 110 | 114 |
| 111 private: | 115 private: |
| 112 TCPClientSocketLibevent* const socket_; | 116 TCPClientSocketLibevent* const socket_; |
| 113 | 117 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 base::TimeTicks connect_start_time_; | 205 base::TimeTicks connect_start_time_; |
| 202 base::TimeDelta connect_time_micros_; | 206 base::TimeDelta connect_time_micros_; |
| 203 int64 num_bytes_read_; | 207 int64 num_bytes_read_; |
| 204 | 208 |
| 205 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent); | 209 DISALLOW_COPY_AND_ASSIGN(TCPClientSocketLibevent); |
| 206 }; | 210 }; |
| 207 | 211 |
| 208 } // namespace net | 212 } // namespace net |
| 209 | 213 |
| 210 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ | 214 #endif // NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ |
| OLD | NEW |