| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 REMOTING_PROTOCOL_SOCKET_READER_BASE_H_ | 5 #ifndef REMOTING_PROTOCOL_SOCKET_READER_BASE_H_ |
| 6 #define REMOTING_PROTOCOL_SOCKET_READER_BASE_H_ | 6 #define REMOTING_PROTOCOL_SOCKET_READER_BASE_H_ |
| 7 | 7 |
| 8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 class IOBuffer; | 12 class IOBuffer; |
| 13 class Socket; | 13 class Socket; |
| 14 } // namespace net | 14 } // namespace net |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 | 17 |
| 18 class SocketReaderBase { | 18 class SocketReaderBase { |
| 19 public: | 19 public: |
| 20 SocketReaderBase(); | 20 SocketReaderBase(); |
| 21 virtual ~SocketReaderBase(); | 21 virtual ~SocketReaderBase(); |
| 22 | 22 |
| 23 // Stops reading. Must be called on the same thread as Init(). | |
| 24 void Close(); | |
| 25 | |
| 26 protected: | 23 protected: |
| 27 void Init(net::Socket* socket); | 24 void Init(net::Socket* socket); |
| 28 virtual void OnDataReceived(net::IOBuffer* buffer, int data_size) = 0; | 25 virtual void OnDataReceived(net::IOBuffer* buffer, int data_size) = 0; |
| 29 | 26 |
| 30 private: | 27 private: |
| 31 void DoRead(); | 28 void DoRead(); |
| 32 void OnRead(int result); | 29 void OnRead(int result); |
| 33 void HandleReadResult(int result); | 30 void HandleReadResult(int result); |
| 34 | 31 |
| 35 net::Socket* socket_; | 32 net::Socket* socket_; |
| 36 bool closed_; | 33 bool closed_; |
| 37 scoped_refptr<net::IOBuffer> read_buffer_; | 34 scoped_refptr<net::IOBuffer> read_buffer_; |
| 38 net::CompletionCallbackImpl<SocketReaderBase> read_callback_; | 35 net::CompletionCallbackImpl<SocketReaderBase> read_callback_; |
| 39 }; | 36 }; |
| 40 | 37 |
| 41 } // namespace remoting | 38 } // namespace remoting |
| 42 | 39 |
| 43 #endif // REMOTING_PROTOCOL_SOCKET_READER_BASE_H_ | 40 #endif // REMOTING_PROTOCOL_SOCKET_READER_BASE_H_ |
| OLD | NEW |