| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SERVER_SOCKET_H_ | 5 #ifndef NET_SOCKET_TCP_SERVER_SOCKET_H_ |
| 6 #define NET_SOCKET_TCP_SERVER_SOCKET_H_ | 6 #define NET_SOCKET_TCP_SERVER_SOCKET_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "net/base/ip_endpoint.h" | 11 #include "net/base/ip_endpoint.h" |
| 11 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 12 #include "net/log/net_log.h" | 13 #include "net/log/net_log.h" |
| 13 #include "net/socket/server_socket.h" | 14 #include "net/socket/server_socket.h" |
| 14 #include "net/socket/tcp_socket.h" | 15 #include "net/socket/tcp_socket.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 class NET_EXPORT TCPServerSocket : public ServerSocket { | 19 class NET_EXPORT TCPServerSocket : public ServerSocket { |
| 19 public: | 20 public: |
| 20 TCPServerSocket(NetLog* net_log, const NetLog::Source& source); | 21 TCPServerSocket(NetLog* net_log, const NetLog::Source& source); |
| 21 ~TCPServerSocket() override; | 22 ~TCPServerSocket() override; |
| 22 | 23 |
| 23 // net::ServerSocket implementation. | 24 // net::ServerSocket implementation. |
| 24 int Listen(const IPEndPoint& address, int backlog) override; | 25 int Listen(const IPEndPoint& address, int backlog) override; |
| 25 int GetLocalAddress(IPEndPoint* address) const override; | 26 int GetLocalAddress(IPEndPoint* address) const override; |
| 26 int Accept(scoped_ptr<StreamSocket>* socket, | 27 int Accept(std::unique_ptr<StreamSocket>* socket, |
| 27 const CompletionCallback& callback) override; | 28 const CompletionCallback& callback) override; |
| 28 | 29 |
| 29 // Detachs from the current thread, to allow the socket to be transferred to | 30 // Detachs from the current thread, to allow the socket to be transferred to |
| 30 // a new thread. Should only be called when the object is no longer used by | 31 // a new thread. Should only be called when the object is no longer used by |
| 31 // the old thread. | 32 // the old thread. |
| 32 void DetachFromThread(); | 33 void DetachFromThread(); |
| 33 | 34 |
| 34 private: | 35 private: |
| 35 // Converts |accepted_socket_| and stores the result in | 36 // Converts |accepted_socket_| and stores the result in |
| 36 // |output_accepted_socket|. | 37 // |output_accepted_socket|. |
| 37 // |output_accepted_socket| is untouched on failure. But |accepted_socket_| is | 38 // |output_accepted_socket| is untouched on failure. But |accepted_socket_| is |
| 38 // set to NULL in any case. | 39 // set to NULL in any case. |
| 39 int ConvertAcceptedSocket(int result, | 40 int ConvertAcceptedSocket( |
| 40 scoped_ptr<StreamSocket>* output_accepted_socket); | 41 int result, |
| 42 std::unique_ptr<StreamSocket>* output_accepted_socket); |
| 41 // Completion callback for calling TCPSocket::Accept(). | 43 // Completion callback for calling TCPSocket::Accept(). |
| 42 void OnAcceptCompleted(scoped_ptr<StreamSocket>* output_accepted_socket, | 44 void OnAcceptCompleted(std::unique_ptr<StreamSocket>* output_accepted_socket, |
| 43 const CompletionCallback& forward_callback, | 45 const CompletionCallback& forward_callback, |
| 44 int result); | 46 int result); |
| 45 | 47 |
| 46 TCPSocket socket_; | 48 TCPSocket socket_; |
| 47 | 49 |
| 48 scoped_ptr<TCPSocket> accepted_socket_; | 50 std::unique_ptr<TCPSocket> accepted_socket_; |
| 49 IPEndPoint accepted_address_; | 51 IPEndPoint accepted_address_; |
| 50 bool pending_accept_; | 52 bool pending_accept_; |
| 51 | 53 |
| 52 DISALLOW_COPY_AND_ASSIGN(TCPServerSocket); | 54 DISALLOW_COPY_AND_ASSIGN(TCPServerSocket); |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 } // namespace net | 57 } // namespace net |
| 56 | 58 |
| 57 #endif // NET_SOCKET_TCP_SERVER_SOCKET_H_ | 59 #endif // NET_SOCKET_TCP_SERVER_SOCKET_H_ |
| OLD | NEW |