Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: net/socket/tcp_listen_socket.cc

Issue 20142003: Remove ref-counting from StreamListenSocket (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/socket/tcp_listen_socket.h ('k') | net/socket/tcp_listen_socket_unittest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
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 #include "net/socket/socket_descriptor.h" 26 #include "net/socket/socket_descriptor.h"
27 27
28 using std::string; 28 using std::string;
29 29
30 namespace net { 30 namespace net {
31 31
32 // static 32 // static
33 scoped_refptr<TCPListenSocket> TCPListenSocket::CreateAndListen( 33 scoped_ptr<TCPListenSocket> TCPListenSocket::CreateAndListen(
34 const string& ip, int port, StreamListenSocket::Delegate* del) { 34 const string& ip, int port, StreamListenSocket::Delegate* del) {
35 SocketDescriptor s = CreateAndBind(ip, port); 35 SocketDescriptor s = CreateAndBind(ip, port);
36 if (s == kInvalidSocket) 36 if (s == kInvalidSocket)
37 return NULL; 37 return scoped_ptr<TCPListenSocket>();
38 scoped_refptr<TCPListenSocket> sock(new TCPListenSocket(s, del)); 38 scoped_ptr<TCPListenSocket> sock(new TCPListenSocket(s, del));
39 sock->Listen(); 39 sock->Listen();
40 return sock; 40 return sock.Pass();
41 } 41 }
42 42
43 TCPListenSocket::TCPListenSocket(SocketDescriptor s, 43 TCPListenSocket::TCPListenSocket(SocketDescriptor s,
44 StreamListenSocket::Delegate* del) 44 StreamListenSocket::Delegate* del)
45 : StreamListenSocket(s, del) { 45 : StreamListenSocket(s, del) {
46 } 46 }
47 47
48 TCPListenSocket::~TCPListenSocket() {} 48 TCPListenSocket::~TCPListenSocket() {}
49 49
50 SocketDescriptor TCPListenSocket::CreateAndBind(const string& ip, int port) { 50 SocketDescriptor TCPListenSocket::CreateAndBind(const string& ip, int port) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return kInvalidSocket; 94 return kInvalidSocket;
95 } 95 }
96 *port = base::NetToHost16(addr.sin_port); 96 *port = base::NetToHost16(addr.sin_port);
97 return s; 97 return s;
98 } 98 }
99 99
100 void TCPListenSocket::Accept() { 100 void TCPListenSocket::Accept() {
101 SocketDescriptor conn = AcceptSocket(); 101 SocketDescriptor conn = AcceptSocket();
102 if (conn == kInvalidSocket) 102 if (conn == kInvalidSocket)
103 return; 103 return;
104 scoped_refptr<TCPListenSocket> sock( 104 scoped_ptr<TCPListenSocket> sock(
105 new TCPListenSocket(conn, socket_delegate_)); 105 new TCPListenSocket(conn, socket_delegate_));
106 // It's up to the delegate to AddRef if it wants to keep it around. 106 // It's up to the delegate to AddRef if it wants to keep it around.
107 #if defined(OS_POSIX) 107 #if defined(OS_POSIX)
108 sock->WatchSocket(WAITING_READ); 108 sock->WatchSocket(WAITING_READ);
109 #endif 109 #endif
110 socket_delegate_->DidAccept(this, sock.get()); 110 socket_delegate_->DidAccept(this, sock.PassAs<StreamListenSocket>());
111 } 111 }
112 112
113 TCPListenSocketFactory::TCPListenSocketFactory(const string& ip, int port) 113 TCPListenSocketFactory::TCPListenSocketFactory(const string& ip, int port)
114 : ip_(ip), 114 : ip_(ip),
115 port_(port) { 115 port_(port) {
116 } 116 }
117 117
118 TCPListenSocketFactory::~TCPListenSocketFactory() {} 118 TCPListenSocketFactory::~TCPListenSocketFactory() {}
119 119
120 scoped_refptr<StreamListenSocket> TCPListenSocketFactory::CreateAndListen( 120 scoped_ptr<StreamListenSocket> TCPListenSocketFactory::CreateAndListen(
121 StreamListenSocket::Delegate* delegate) const { 121 StreamListenSocket::Delegate* delegate) const {
122 return TCPListenSocket::CreateAndListen(ip_, port_, delegate); 122 return TCPListenSocket::CreateAndListen(ip_, port_, delegate)
123 .PassAs<StreamListenSocket>();
123 } 124 }
124 125
125 } // namespace net 126 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_listen_socket.h ('k') | net/socket/tcp_listen_socket_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698