xref: /aosp_15_r20/external/cronet/net/test/embedded_test_server/simple_connection_listener.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/test/embedded_test_server/simple_connection_listener.h"
6 
7 #include "base/location.h"
8 #include "net/socket/stream_socket.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace net::test_server {
12 
SimpleConnectionListener(int expected_connections,AllowAdditionalConnections allow_additional_connections)13 SimpleConnectionListener::SimpleConnectionListener(
14     int expected_connections,
15     AllowAdditionalConnections allow_additional_connections)
16     : expected_connections_(expected_connections),
17       allow_additional_connections_(allow_additional_connections) {}
18 
19 SimpleConnectionListener::~SimpleConnectionListener() = default;
20 
AcceptedSocket(std::unique_ptr<StreamSocket> socket)21 std::unique_ptr<StreamSocket> SimpleConnectionListener::AcceptedSocket(
22     std::unique_ptr<StreamSocket> socket) {
23   ++seen_connections_;
24   if (allow_additional_connections_ != ALLOW_ADDITIONAL_CONNECTIONS)
25     EXPECT_LE(seen_connections_, expected_connections_);
26   if (seen_connections_ == expected_connections_)
27     run_loop_.Quit();
28   return socket;
29 }
30 
ReadFromSocket(const StreamSocket & socket,int rv)31 void SimpleConnectionListener::ReadFromSocket(const StreamSocket& socket,
32                                               int rv) {}
33 
WaitForConnections()34 void SimpleConnectionListener::WaitForConnections() {
35   run_loop_.Run();
36 }
37 
OnResponseCompletedSuccessfully(std::unique_ptr<StreamSocket> socket)38 void SimpleConnectionListener::OnResponseCompletedSuccessfully(
39     std::unique_ptr<StreamSocket> socket) {}
40 
41 }  // namespace net::test_server
42