• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef QUICHE_QUIC_CORE_SOCKET_FACTORY_H_
6 #define QUICHE_QUIC_CORE_SOCKET_FACTORY_H_
7 
8 #include <memory>
9 
10 #include "quiche/quic/core/connecting_client_socket.h"
11 #include "quiche/quic/core/quic_types.h"
12 #include "quiche/quic/platform/api/quic_socket_address.h"
13 #include "quiche/common/platform/api/quiche_export.h"
14 
15 namespace quic {
16 
17 // A factory to create objects of type Socket and derived interfaces.
18 class QUICHE_EXPORT SocketFactory {
19  public:
20   virtual ~SocketFactory() = default;
21 
22   // Will use platform default buffer size if `receive_buffer_size` or
23   // `send_buffer_size` is zero. If `async_visitor` is null, async operations
24   // must not be called on the created socket. If `async_visitor` is non-null,
25   // it must outlive the created socket.
26   virtual std::unique_ptr<ConnectingClientSocket> CreateTcpClientSocket(
27       const quic::QuicSocketAddress& peer_address,
28       QuicByteCount receive_buffer_size, QuicByteCount send_buffer_size,
29       ConnectingClientSocket::AsyncVisitor* async_visitor) = 0;
30 
31   // Will use platform default buffer size if `receive_buffer_size` or
32   // `send_buffer_size` is zero. If `async_visitor` is null, async operations
33   // must not be called on the created socket. If `async_visitor` is non-null,
34   // it must outlive the created socket.
35   //
36   // TODO(ericorth): Consider creating a sub-interface for connecting UDP
37   // sockets with additional functionality, e.g. sendto, if needed.
38   virtual std::unique_ptr<ConnectingClientSocket>
39   CreateConnectingUdpClientSocket(
40       const quic::QuicSocketAddress& peer_address,
41       QuicByteCount receive_buffer_size, QuicByteCount send_buffer_size,
42       ConnectingClientSocket::AsyncVisitor* async_visitor) = 0;
43 };
44 
45 }  // namespace quic
46 
47 #endif  // QUICHE_QUIC_CORE_SOCKET_FACTORY_H_
48