1 /*
2  *  Copyright 2011 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef P2P_BASE_BASIC_PACKET_SOCKET_FACTORY_H_
12 #define P2P_BASE_BASIC_PACKET_SOCKET_FACTORY_H_
13 
14 #include <string>
15 
16 #include "api/packet_socket_factory.h"
17 
18 namespace rtc {
19 
20 class AsyncSocket;
21 class SocketFactory;
22 class Thread;
23 
24 class BasicPacketSocketFactory : public PacketSocketFactory {
25  public:
26   BasicPacketSocketFactory();
27   explicit BasicPacketSocketFactory(Thread* thread);
28   explicit BasicPacketSocketFactory(SocketFactory* socket_factory);
29   ~BasicPacketSocketFactory() override;
30 
31   AsyncPacketSocket* CreateUdpSocket(const SocketAddress& local_address,
32                                      uint16_t min_port,
33                                      uint16_t max_port) override;
34   AsyncPacketSocket* CreateServerTcpSocket(const SocketAddress& local_address,
35                                            uint16_t min_port,
36                                            uint16_t max_port,
37                                            int opts) override;
38   AsyncPacketSocket* CreateClientTcpSocket(
39       const SocketAddress& local_address,
40       const SocketAddress& remote_address,
41       const ProxyInfo& proxy_info,
42       const std::string& user_agent,
43       const PacketSocketTcpOptions& tcp_options) override;
44 
45   AsyncResolverInterface* CreateAsyncResolver() override;
46 
47  private:
48   int BindSocket(AsyncSocket* socket,
49                  const SocketAddress& local_address,
50                  uint16_t min_port,
51                  uint16_t max_port);
52 
53   SocketFactory* socket_factory();
54 
55   Thread* thread_;
56   SocketFactory* socket_factory_;
57 };
58 
59 }  // namespace rtc
60 
61 #endif  // P2P_BASE_BASIC_PACKET_SOCKET_FACTORY_H_
62