| 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 #include "net/socket/tcp_listen_socket.h" | 5 #include "net/socket/tcp_listen_socket.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 // winsock2.h must be included first in order to ensure it is included before | 8 // winsock2.h must be included first in order to ensure it is included before |
| 9 // windows.h. | 9 // windows.h. |
| 10 #include <winsock2.h> | 10 #include <winsock2.h> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/threading/platform_thread.h" | 22 #include "base/threading/platform_thread.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 #include "net/base/winsock_init.h" | 25 #include "net/base/winsock_init.h" |
| 26 | 26 |
| 27 using std::string; | 27 using std::string; |
| 28 | 28 |
| 29 namespace net { | 29 namespace net { |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 scoped_refptr<TCPListenSocket> TCPListenSocket::CreateAndListen( | 32 scoped_ptr<TCPListenSocket> TCPListenSocket::CreateAndListen( |
| 33 const string& ip, int port, StreamListenSocket::Delegate* del) { | 33 const string& ip, int port, StreamListenSocket::Delegate* del) { |
| 34 SocketDescriptor s = CreateAndBind(ip, port); | 34 SocketDescriptor s = CreateAndBind(ip, port); |
| 35 if (s == kInvalidSocket) | 35 if (s == kInvalidSocket) |
| 36 return NULL; | 36 return scoped_ptr<TCPListenSocket>(); |
| 37 scoped_refptr<TCPListenSocket> sock(new TCPListenSocket(s, del)); | 37 scoped_ptr<TCPListenSocket> sock(new TCPListenSocket(s, del)); |
| 38 sock->Listen(); | 38 sock->Listen(); |
| 39 return sock; | 39 return sock.Pass(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 TCPListenSocket::TCPListenSocket(SocketDescriptor s, | 42 TCPListenSocket::TCPListenSocket(SocketDescriptor s, |
| 43 StreamListenSocket::Delegate* del) | 43 StreamListenSocket::Delegate* del) |
| 44 : StreamListenSocket(s, del) { | 44 : StreamListenSocket(s, del) { |
| 45 } | 45 } |
| 46 | 46 |
| 47 TCPListenSocket::~TCPListenSocket() {} | 47 TCPListenSocket::~TCPListenSocket() {} |
| 48 | 48 |
| 49 SocketDescriptor TCPListenSocket::CreateAndBind(const string& ip, int port) { | 49 SocketDescriptor TCPListenSocket::CreateAndBind(const string& ip, int port) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 return kInvalidSocket; | 97 return kInvalidSocket; |
| 98 } | 98 } |
| 99 *port = base::NetToHost16(addr.sin_port); | 99 *port = base::NetToHost16(addr.sin_port); |
| 100 return s; | 100 return s; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void TCPListenSocket::Accept() { | 103 void TCPListenSocket::Accept() { |
| 104 SocketDescriptor conn = AcceptSocket(); | 104 SocketDescriptor conn = AcceptSocket(); |
| 105 if (conn == kInvalidSocket) | 105 if (conn == kInvalidSocket) |
| 106 return; | 106 return; |
| 107 scoped_refptr<TCPListenSocket> sock( | 107 scoped_ptr<TCPListenSocket> sock( |
| 108 new TCPListenSocket(conn, socket_delegate_)); | 108 new TCPListenSocket(conn, socket_delegate_)); |
| 109 // It's up to the delegate to AddRef if it wants to keep it around. | 109 // It's up to the delegate to AddRef if it wants to keep it around. |
| 110 #if defined(OS_POSIX) | 110 #if defined(OS_POSIX) |
| 111 sock->WatchSocket(WAITING_READ); | 111 sock->WatchSocket(WAITING_READ); |
| 112 #endif | 112 #endif |
| 113 socket_delegate_->DidAccept(this, sock.get()); | 113 socket_delegate_->DidAccept(this, sock.PassAs<StreamListenSocket>()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 TCPListenSocketFactory::TCPListenSocketFactory(const string& ip, int port) | 116 TCPListenSocketFactory::TCPListenSocketFactory(const string& ip, int port) |
| 117 : ip_(ip), | 117 : ip_(ip), |
| 118 port_(port) { | 118 port_(port) { |
| 119 } | 119 } |
| 120 | 120 |
| 121 TCPListenSocketFactory::~TCPListenSocketFactory() {} | 121 TCPListenSocketFactory::~TCPListenSocketFactory() {} |
| 122 | 122 |
| 123 scoped_refptr<StreamListenSocket> TCPListenSocketFactory::CreateAndListen( | 123 scoped_ptr<StreamListenSocket> TCPListenSocketFactory::CreateAndListen( |
| 124 StreamListenSocket::Delegate* delegate) const { | 124 StreamListenSocket::Delegate* delegate) const { |
| 125 return TCPListenSocket::CreateAndListen(ip_, port_, delegate); | 125 return TCPListenSocket::CreateAndListen(ip_, port_, delegate) |
| 126 .PassAs<StreamListenSocket>(); |
| 126 } | 127 } |
| 127 | 128 |
| 128 } // namespace net | 129 } // namespace net |
| OLD | NEW |