roll skia to 4276
[chromium-blink-merge.git] / net / base / tcp_listen_socket.h
blob739856598e5df308e92839d4a696be6569c9004d
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_BASE_TCP_LISTEN_SOCKET_H_
6 #define NET_BASE_TCP_LISTEN_SOCKET_H_
7 #pragma once
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "net/base/net_export.h"
14 #include "net/base/stream_listen_socket.h"
16 namespace net {
18 // Implements a TCP socket. Note that this is ref counted.
19 class NET_EXPORT TCPListenSocket : public StreamListenSocket {
20 public:
21 // Listen on port for the specified IP address. Use 127.0.0.1 to only
22 // accept local connections.
23 static scoped_refptr<TCPListenSocket> CreateAndListen(
24 const std::string& ip, int port, StreamListenSocket::Delegate* del);
26 protected:
27 friend class scoped_refptr<TCPListenSocket>;
29 TCPListenSocket(SocketDescriptor s, StreamListenSocket::Delegate* del);
30 virtual ~TCPListenSocket();
32 static SocketDescriptor CreateAndBind(const std::string& ip, int port);
34 // Implements StreamListenSocket::Accept.
35 virtual void Accept() OVERRIDE;
37 private:
38 DISALLOW_COPY_AND_ASSIGN(TCPListenSocket);
41 // Factory that can be used to instantiate TCPListenSocket.
42 class NET_EXPORT TCPListenSocketFactory : public StreamListenSocketFactory {
43 public:
44 TCPListenSocketFactory(const std::string& ip, int port);
45 virtual ~TCPListenSocketFactory();
47 // StreamListenSocketFactory overrides.
48 virtual scoped_refptr<StreamListenSocket> CreateAndListen(
49 StreamListenSocket::Delegate* delegate) const OVERRIDE;
51 private:
52 const std::string ip_;
53 const int port_;
55 DISALLOW_COPY_AND_ASSIGN(TCPListenSocketFactory);
58 } // namespace net
60 #endif // NET_BASE_TCP_LISTEN_SOCKET_H_