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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
#define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
#pragma once
#include <string>
#include "chrome/browser/extensions/api/socket/socket.h"
// This looks like it should be forward-declarable, but it does some tricky
// moves that make it easier to just include it.
#include "net/socket/tcp_client_socket.h"
namespace net {
class Socket;
}
namespace extensions {
class APIResourceEventNotifier;
class TCPSocket : public Socket {
public:
explicit TCPSocket(APIResourceEventNotifier* event_notifier);
virtual ~TCPSocket();
virtual void Connect(const std::string& address,
int port,
const CompletionCallback& callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual int Bind(const std::string& address, int port) OVERRIDE;
virtual void Read(int count,
const ReadCompletionCallback& callback) OVERRIDE;
virtual void RecvFrom(int count,
const RecvFromCompletionCallback& callback) OVERRIDE;
virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer,
int byte_count,
const std::string& address,
int port,
const CompletionCallback& callback) OVERRIDE;
virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE;
virtual bool SetNoDelay(bool no_delay) OVERRIDE;
static TCPSocket* CreateSocketForTesting(
net::TCPClientSocket* tcp_client_socket,
APIResourceEventNotifier* event_notifier);
protected:
virtual int WriteImpl(net::IOBuffer* io_buffer,
int io_buffer_size,
const net::CompletionCallback& callback) OVERRIDE;
private:
void OnConnectComplete(int result);
void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
int result);
TCPSocket(net::TCPClientSocket* tcp_client_socket,
APIResourceEventNotifier* event_notifier);
scoped_ptr<net::TCPClientSocket> socket_;
CompletionCallback connect_callback_;
ReadCompletionCallback read_callback_;
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
|