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

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, 1 month 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
« net/base/tcp_listen_socket.h ('K') | « net/base/tcp_listen_socket.h ('k') | no next file » | 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/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 int TCPListenSocket::GetBindedPort(SocketDescriptor s) {
Mark Seaborn 2012/10/23 01:14:50 Should the return type be uint16 to match NetToHos
halyavin 2012/10/23 11:59:29 port numbers are generally saved in int in Chrome.
80 sockaddr_in addr;
81 socklen_t addr_size = sizeof(addr);
82 bool failed = getsockname(s, (struct sockaddr *) &addr, &addr_size) != 0;
83 if (addr_size != sizeof(addr)) {
84 failed = true;
85 }
86 if (failed) {
87 LOG(ERROR) << "Could not determine binded port, getsockname() failed";
88 #if defined(OS_WIN)
89 closesocket(s);
90 #elif defined(OS_POSIX)
91 close(s);
92 #endif
93 return -1;
94 }
95 return base::NetToHost16(addr.sin_port);
96 }
97
79 void TCPListenSocket::Accept() { 98 void TCPListenSocket::Accept() {
80 SocketDescriptor conn = AcceptSocket(); 99 SocketDescriptor conn = AcceptSocket();
81 if (conn == kInvalidSocket) 100 if (conn == kInvalidSocket)
82 return; 101 return;
83 scoped_refptr<TCPListenSocket> sock( 102 scoped_refptr<TCPListenSocket> sock(
84 new TCPListenSocket(conn, socket_delegate_)); 103 new TCPListenSocket(conn, socket_delegate_));
85 // It's up to the delegate to AddRef if it wants to keep it around. 104 // It's up to the delegate to AddRef if it wants to keep it around.
86 #if defined(OS_POSIX) 105 #if defined(OS_POSIX)
87 sock->WatchSocket(WAITING_READ); 106 sock->WatchSocket(WAITING_READ);
88 #endif 107 #endif
89 socket_delegate_->DidAccept(this, sock); 108 socket_delegate_->DidAccept(this, sock);
90 } 109 }
91 110
92 TCPListenSocketFactory::TCPListenSocketFactory(const string& ip, int port) 111 TCPListenSocketFactory::TCPListenSocketFactory(const string& ip, int port)
93 : ip_(ip), 112 : ip_(ip),
94 port_(port) { 113 port_(port) {
95 } 114 }
96 115
97 TCPListenSocketFactory::~TCPListenSocketFactory() {} 116 TCPListenSocketFactory::~TCPListenSocketFactory() {}
98 117
99 scoped_refptr<StreamListenSocket> TCPListenSocketFactory::CreateAndListen( 118 scoped_refptr<StreamListenSocket> TCPListenSocketFactory::CreateAndListen(
100 StreamListenSocket::Delegate* delegate) const { 119 StreamListenSocket::Delegate* delegate) const {
101 return TCPListenSocket::CreateAndListen(ip_, port_, delegate); 120 return TCPListenSocket::CreateAndListen(ip_, port_, delegate);
102 } 121 }
103 122
104 } // namespace net 123 } // namespace net
OLDNEW
« net/base/tcp_listen_socket.h ('K') | « net/base/tcp_listen_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698