1 // Copyright (c) 2012 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.
5 #ifndef NET_SOCKET_TCP_LISTEN_SOCKET_H_
6 #define NET_SOCKET_TCP_LISTEN_SOCKET_H_
10 #include "base/basictypes.h"
11 #include "net/base/net_export.h"
12 #include "net/socket/socket_descriptor.h"
13 #include "net/socket/stream_listen_socket.h"
17 // Implements a TCP socket.
18 class NET_EXPORT TCPListenSocket
: public StreamListenSocket
{
20 ~TCPListenSocket() override
;
21 // Listen on port for the specified IP address. Use 127.0.0.1 to only
22 // accept local connections.
23 static scoped_ptr
<TCPListenSocket
> CreateAndListen(
24 const std::string
& ip
, int port
, StreamListenSocket::Delegate
* del
);
26 // Get raw TCP socket descriptor bound to ip:port.
27 static SocketDescriptor
CreateAndBind(const std::string
& ip
, int port
);
29 // Get raw TCP socket descriptor bound to ip and return port it is bound to.
30 static SocketDescriptor
CreateAndBindAnyPort(const std::string
& ip
,
34 TCPListenSocket(SocketDescriptor s
, StreamListenSocket::Delegate
* del
);
36 // Implements StreamListenSocket::Accept.
37 void Accept() override
;
40 DISALLOW_COPY_AND_ASSIGN(TCPListenSocket
);
43 // Factory that can be used to instantiate TCPListenSocket.
44 class NET_EXPORT TCPListenSocketFactory
: public StreamListenSocketFactory
{
46 TCPListenSocketFactory(const std::string
& ip
, int port
);
47 ~TCPListenSocketFactory() override
;
49 // StreamListenSocketFactory overrides.
50 scoped_ptr
<StreamListenSocket
> CreateAndListen(
51 StreamListenSocket::Delegate
* delegate
) const override
;
54 const std::string ip_
;
57 DISALLOW_COPY_AND_ASSIGN(TCPListenSocketFactory
);
62 #endif // NET_SOCKET_TCP_LISTEN_SOCKET_H_