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

Side by Side Diff: chrome/test/chromedriver/net/websocket.cc

Issue 1879863002: Reland of [chromedriver] Listen on IPv6 on IPv6-only hosts (part 2). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better logging Created 4 years, 8 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
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 "chrome/test/chromedriver/net/websocket.h" 5 #include "chrome/test/chromedriver/net/websocket.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include <memory> 11 #include <memory>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/base64.h" 14 #include "base/base64.h"
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
17 #include "base/json/json_writer.h"
17 #include "base/rand_util.h" 18 #include "base/rand_util.h"
18 #include "base/sha1.h" 19 #include "base/sha1.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/values.h"
21 #include "build/build_config.h" 23 #include "build/build_config.h"
22 #include "net/base/address_list.h" 24 #include "net/base/address_list.h"
23 #include "net/base/io_buffer.h" 25 #include "net/base/io_buffer.h"
24 #include "net/base/ip_address.h" 26 #include "net/base/ip_address.h"
25 #include "net/base/ip_endpoint.h" 27 #include "net/base/ip_endpoint.h"
26 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
27 #include "net/base/sys_addrinfo.h" 29 #include "net/base/sys_addrinfo.h"
28 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
29 #include "net/http/http_util.h" 31 #include "net/http/http_util.h"
30 #include "net/websockets/websocket_frame.h" 32 #include "net/websockets/websocket_frame.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 70
69 void WebSocket::Connect(const net::CompletionCallback& callback) { 71 void WebSocket::Connect(const net::CompletionCallback& callback) {
70 CHECK(thread_checker_.CalledOnValidThread()); 72 CHECK(thread_checker_.CalledOnValidThread());
71 CHECK_EQ(INITIALIZED, state_); 73 CHECK_EQ(INITIALIZED, state_);
72 74
73 net::IPAddress address; 75 net::IPAddress address;
74 net::AddressList addresses; 76 net::AddressList addresses;
75 uint16_t port = static_cast<uint16_t>(url_.EffectiveIntPort()); 77 uint16_t port = static_cast<uint16_t>(url_.EffectiveIntPort());
76 if (ParseURLHostnameToAddress(url_.host(), &address)) { 78 if (ParseURLHostnameToAddress(url_.host(), &address)) {
77 addresses = net::AddressList::CreateFromIPAddress(address, port); 79 addresses = net::AddressList::CreateFromIPAddress(address, port);
78 } else if (!ResolveHost(url_.HostNoBrackets(), port, &addresses)) { 80 } else {
79 callback.Run(net::ERR_ADDRESS_UNREACHABLE); 81 if (!ResolveHost(url_.HostNoBrackets(), port, &addresses)) {
80 return; 82 callback.Run(net::ERR_ADDRESS_UNREACHABLE);
83 return;
84 }
85 base::ListValue endpoints;
86 for (auto endpoint : addresses)
87 endpoints.AppendString(endpoint.ToStringWithoutPort());
88 std::string json;
89 CHECK(base::JSONWriter::Write(endpoints, &json));
90 VLOG(0) << "resolved " << url_.HostNoBrackets() << " to " << json;
81 } 91 }
82 92
83 net::NetLog::Source source; 93 net::NetLog::Source source;
84 socket_.reset(new net::TCPClientSocket(addresses, NULL, NULL, source)); 94 socket_.reset(new net::TCPClientSocket(addresses, NULL, NULL, source));
85 95
86 state_ = CONNECTING; 96 state_ = CONNECTING;
87 connect_callback_ = callback; 97 connect_callback_ = callback;
88 int code = socket_->Connect(base::Bind( 98 int code = socket_->Connect(base::Bind(
89 &WebSocket::OnSocketConnect, base::Unretained(this))); 99 &WebSocket::OnSocketConnect, base::Unretained(this)));
90 if (code != net::ERR_IO_PENDING) 100 if (code != net::ERR_IO_PENDING)
(...skipping 18 matching lines...) Expand all
109 119
110 std::string masked_message = message; 120 std::string masked_message = message;
111 net::MaskWebSocketFramePayload( 121 net::MaskWebSocketFramePayload(
112 masking_key, 0, &masked_message[0], masked_message.length()); 122 masking_key, 0, &masked_message[0], masked_message.length());
113 Write(header_str + masked_message); 123 Write(header_str + masked_message);
114 return true; 124 return true;
115 } 125 }
116 126
117 void WebSocket::OnSocketConnect(int code) { 127 void WebSocket::OnSocketConnect(int code) {
118 if (code != net::OK) { 128 if (code != net::OK) {
129 VLOG(1) << "failed to connect to " << url_.HostNoBrackets() << " (error "
130 << code << ")";
119 Close(code); 131 Close(code);
120 return; 132 return;
121 } 133 }
122 134
123 base::Base64Encode(base::RandBytesAsString(16), &sec_key_); 135 base::Base64Encode(base::RandBytesAsString(16), &sec_key_);
124 std::string handshake = base::StringPrintf( 136 std::string handshake = base::StringPrintf(
125 "GET %s HTTP/1.1\r\n" 137 "GET %s HTTP/1.1\r\n"
126 "Host: %s\r\n" 138 "Host: %s\r\n"
127 "Upgrade: websocket\r\n" 139 "Upgrade: websocket\r\n"
128 "Connection: Upgrade\r\n" 140 "Connection: Upgrade\r\n"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 266
255 void WebSocket::Close(int code) { 267 void WebSocket::Close(int code) {
256 socket_->Disconnect(); 268 socket_->Disconnect();
257 if (!connect_callback_.is_null()) 269 if (!connect_callback_.is_null())
258 InvokeConnectCallback(code); 270 InvokeConnectCallback(code);
259 if (state_ == OPEN) 271 if (state_ == OPEN)
260 listener_->OnClose(); 272 listener_->OnClose();
261 273
262 state_ = CLOSED; 274 state_ = CLOSED;
263 } 275 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/net/net_util.cc ('k') | chrome/test/chromedriver/server/chromedriver_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698