| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef NET_BASE_TCP_LISTEN_SOCKET_H_ | |
| 6 #define NET_BASE_TCP_LISTEN_SOCKET_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "net/base/net_export.h" | |
| 13 #include "net/base/stream_listen_socket.h" | |
| 14 | |
| 15 namespace net { | |
| 16 | |
| 17 // Implements a TCP socket. Note that this is ref counted. | |
| 18 class NET_EXPORT TCPListenSocket : public StreamListenSocket { | |
| 19 public: | |
| 20 // Listen on port for the specified IP address. Use 127.0.0.1 to only | |
| 21 // accept local connections. | |
| 22 static scoped_refptr<TCPListenSocket> CreateAndListen( | |
| 23 const std::string& ip, int port, StreamListenSocket::Delegate* del); | |
| 24 | |
| 25 // Get raw TCP socket descriptor bound to ip:port. | |
| 26 static SocketDescriptor CreateAndBind(const std::string& ip, int port); | |
| 27 | |
| 28 // Get raw TCP socket descriptor bound to ip and return port it is bound to. | |
| 29 static SocketDescriptor CreateAndBindAnyPort(const std::string& ip, | |
| 30 int* port); | |
| 31 | |
| 32 protected: | |
| 33 friend class scoped_refptr<TCPListenSocket>; | |
| 34 | |
| 35 TCPListenSocket(SocketDescriptor s, StreamListenSocket::Delegate* del); | |
| 36 virtual ~TCPListenSocket(); | |
| 37 | |
| 38 // Implements StreamListenSocket::Accept. | |
| 39 virtual void Accept() OVERRIDE; | |
| 40 | |
| 41 private: | |
| 42 DISALLOW_COPY_AND_ASSIGN(TCPListenSocket); | |
| 43 }; | |
| 44 | |
| 45 // Factory that can be used to instantiate TCPListenSocket. | |
| 46 class NET_EXPORT TCPListenSocketFactory : public StreamListenSocketFactory { | |
| 47 public: | |
| 48 TCPListenSocketFactory(const std::string& ip, int port); | |
| 49 virtual ~TCPListenSocketFactory(); | |
| 50 | |
| 51 // StreamListenSocketFactory overrides. | |
| 52 virtual scoped_refptr<StreamListenSocket> CreateAndListen( | |
| 53 StreamListenSocket::Delegate* delegate) const OVERRIDE; | |
| 54 | |
| 55 private: | |
| 56 const std::string ip_; | |
| 57 const int port_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(TCPListenSocketFactory); | |
| 60 }; | |
| 61 | |
| 62 } // namespace net | |
| 63 | |
| 64 #endif // NET_BASE_TCP_LISTEN_SOCKET_H_ | |
| OLD | NEW |