blob: f89cd7a124fa7e1f97035cfa1c7f00df68fff4d6 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// 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 REMOTING_PROTOCOL_CONNECTION_TESTER_H_
#define REMOTING_PROTOCOL_CONNECTION_TESTER_H_
#include <vector>
#include "base/memory/ref_counted.h"
class MessageLoop;
namespace net {
class DrainableIOBuffer;
class GrowableIOBuffer;
class IOBuffer;
class Socket;
class StreamSocket;
} // namespace net
namespace remoting {
namespace protocol {
// This class is used by unit tests to verify that a connection
// between two sockets works properly, i.e. data is delivered from one
// end to the other.
class StreamConnectionTester {
public:
StreamConnectionTester(net::StreamSocket* client_socket,
net::StreamSocket* host_socket,
int message_size,
int message_count);
~StreamConnectionTester();
void Start();
bool done() { return done_; }
void CheckResults();
protected:
void Done();
void InitBuffers();
void DoWrite();
void OnWritten(int result);
void HandleWriteResult(int result);
void DoRead();
void OnRead(int result);
void HandleReadResult(int result);
private:
MessageLoop* message_loop_;
net::StreamSocket* host_socket_;
net::StreamSocket* client_socket_;
int message_size_;
int test_data_size_;
bool done_;
scoped_refptr<net::DrainableIOBuffer> output_buffer_;
scoped_refptr<net::GrowableIOBuffer> input_buffer_;
int write_errors_;
int read_errors_;
};
class DatagramConnectionTester {
public:
DatagramConnectionTester(net::Socket* client_socket,
net::Socket* host_socket,
int message_size,
int message_count,
int delay_ms);
~DatagramConnectionTester() ;
void Start();
void CheckResults();
private:
void Done();
void DoWrite();
void OnWritten(int result);
void HandleWriteResult(int result);
void DoRead();
void OnRead(int result);
void HandleReadResult(int result);
MessageLoop* message_loop_;
net::Socket* host_socket_;
net::Socket* client_socket_;
int message_size_;
int message_count_;
int delay_ms_;
bool done_;
std::vector<scoped_refptr<net::IOBuffer> > sent_packets_;
scoped_refptr<net::IOBuffer> read_buffer_;
int write_errors_;
int read_errors_;
int packets_sent_;
int packets_received_;
int bad_packets_received_;
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_CONNECTION_TESTER_H_
|