summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/socket_reader_base.h
blob: 5e366f89708b3185167f212bdfac19154dbf6f52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_PROTOCOL_SOCKET_READER_BASE_H_
#define REMOTING_PROTOCOL_SOCKET_READER_BASE_H_

#include "base/ref_counted.h"
#include "net/base/completion_callback.h"

namespace net {
class IOBuffer;
class Socket;
}  // namespace net

namespace remoting {

class SocketReaderBase {
 public:
  SocketReaderBase();
  virtual ~SocketReaderBase();

 protected:
  void Init(net::Socket* socket);
  virtual void OnDataReceived(net::IOBuffer* buffer, int data_size) = 0;

 private:
  void DoRead();
  void OnRead(int result);
  void HandleReadResult(int result);

  net::Socket* socket_;
  bool closed_;
  scoped_refptr<net::IOBuffer> read_buffer_;
  net::CompletionCallbackImpl<SocketReaderBase> read_callback_;
};

}  // namespace remoting

#endif  // REMOTING_PROTOCOL_SOCKET_READER_BASE_H_