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