summaryrefslogtreecommitdiffstats
path: root/blimp/net/tcp_client_transport.h
blob: 3242883e0519464c7daf21413e2e6cb36272de58 (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
41
42
43
44
45
46
47
48
49
50
// Copyright 2015 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 BLIMP_NET_TCP_CLIENT_TRANSPORT_H_
#define BLIMP_NET_TCP_CLIENT_TRANSPORT_H_

#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "blimp/net/blimp_net_export.h"
#include "blimp/net/blimp_transport.h"
#include "net/base/address_list.h"
#include "net/base/net_errors.h"

namespace net {
class NetLog;
class StreamSocket;
}  // namespace net

namespace blimp {

class BlimpConnection;

// BlimpTransport which creates a TCP connection to one of the specified
// |addresses| on each call to Connect().
class BLIMP_NET_EXPORT TCPClientTransport : public BlimpTransport {
 public:
  TCPClientTransport(const net::AddressList& addresses, net::NetLog* net_log);
  ~TCPClientTransport() override;

  // BlimpTransport implementation.
  void Connect(const net::CompletionCallback& callback) override;
  scoped_ptr<BlimpConnection> TakeConnection() override;
  const std::string GetName() const override;

 private:
  void OnTCPConnectComplete(int result);

  net::AddressList addresses_;
  net::NetLog* net_log_;
  scoped_ptr<net::StreamSocket> socket_;
  net::CompletionCallback connect_callback_;

  DISALLOW_COPY_AND_ASSIGN(TCPClientTransport);
};

}  // namespace blimp

#endif  // BLIMP_NET_TCP_CLIENT_TRANSPORT_H_