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

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

Issue 11236025: Test that debug stub works with browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: rebase Created 8 years 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
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/base/tcp_listen_socket.h" 5 #include "net/base/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #elif defined(OS_POSIX) 69 #elif defined(OS_POSIX)
70 close(s); 70 close(s);
71 #endif 71 #endif
72 LOG(ERROR) << "Could not bind socket to " << ip << ":" << port; 72 LOG(ERROR) << "Could not bind socket to " << ip << ":" << port;
73 s = kInvalidSocket; 73 s = kInvalidSocket;
74 } 74 }
75 } 75 }
76 return s; 76 return s;
77 } 77 }
78 78
79 SocketDescriptor TCPListenSocket::CreateAndBindAnyPort(const std::string& ip,
Mark Seaborn 2012/12/04 21:46:42 Nit: s/std::string/string/ to match the rest of th
halyavin 2012/12/05 10:05:57 Done.
80 int* port) {
81 SocketDescriptor s = CreateAndBind(ip, 0);
82 sockaddr_in addr;
83 socklen_t addr_size = sizeof(addr);
84 bool failed = getsockname(s, (struct sockaddr *) &addr, &addr_size) != 0;
85 if (addr_size != sizeof(addr)) {
86 failed = true;
87 }
88 if (failed) {
89 LOG(ERROR) << "Could not determine binded port, getsockname() failed";
Mark Seaborn 2012/12/04 21:46:42 'binded' -> 'bound'
halyavin 2012/12/05 10:05:57 Done.
90 #if defined(OS_WIN)
91 closesocket(s);
92 #elif defined(OS_POSIX)
93 close(s);
94 #endif
95 return kInvalidSocket;
96 }
97 *port = base::NetToHost16(addr.sin_port);
98 return s;
99 }
100
79 void TCPListenSocket::Accept() { 101 void TCPListenSocket::Accept() {
80 SocketDescriptor conn = AcceptSocket(); 102 SocketDescriptor conn = AcceptSocket();
81 if (conn == kInvalidSocket) 103 if (conn == kInvalidSocket)
82 return; 104 return;
83 scoped_refptr<TCPListenSocket> sock( 105 scoped_refptr<TCPListenSocket> sock(
84 new TCPListenSocket(conn, socket_delegate_)); 106 new TCPListenSocket(conn, socket_delegate_));
85 // It's up to the delegate to AddRef if it wants to keep it around. 107 // It's up to the delegate to AddRef if it wants to keep it around.
86 #if defined(OS_POSIX) 108 #if defined(OS_POSIX)
87 sock->WatchSocket(WAITING_READ); 109 sock->WatchSocket(WAITING_READ);
88 #endif 110 #endif
89 socket_delegate_->DidAccept(this, sock); 111 socket_delegate_->DidAccept(this, sock);
90 } 112 }
91 113
92 TCPListenSocketFactory::TCPListenSocketFactory(const string& ip, int port) 114 TCPListenSocketFactory::TCPListenSocketFactory(const string& ip, int port)
93 : ip_(ip), 115 : ip_(ip),
94 port_(port) { 116 port_(port) {
95 } 117 }
96 118
97 TCPListenSocketFactory::~TCPListenSocketFactory() {} 119 TCPListenSocketFactory::~TCPListenSocketFactory() {}
98 120
99 scoped_refptr<StreamListenSocket> TCPListenSocketFactory::CreateAndListen( 121 scoped_refptr<StreamListenSocket> TCPListenSocketFactory::CreateAndListen(
100 StreamListenSocket::Delegate* delegate) const { 122 StreamListenSocket::Delegate* delegate) const {
101 return TCPListenSocket::CreateAndListen(ip_, port_, delegate); 123 return TCPListenSocket::CreateAndListen(ip_, port_, delegate);
102 } 124 }
103 125
104 } // namespace net 126 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698