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

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

Issue 451383002: Plumbing for TCP FastOpen for SSL sockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed one shared bool to a normal bool Created 6 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_socket.h" 5 #include "net/socket/tcp_socket.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <netinet/tcp.h> 8 #include <netinet/tcp.h>
9 #include <sys/socket.h> 9 #include <sys/socket.h>
10 10
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 void TCPSocketLibevent::Close() { 362 void TCPSocketLibevent::Close() {
363 socket_.reset(); 363 socket_.reset();
364 tcp_fastopen_connected_ = false; 364 tcp_fastopen_connected_ = false;
365 fast_open_status_ = FAST_OPEN_STATUS_UNKNOWN; 365 fast_open_status_ = FAST_OPEN_STATUS_UNKNOWN;
366 } 366 }
367 367
368 bool TCPSocketLibevent::UsingTCPFastOpen() const { 368 bool TCPSocketLibevent::UsingTCPFastOpen() const {
369 return use_tcp_fastopen_; 369 return use_tcp_fastopen_;
370 } 370 }
371 371
372 void TCPSocketLibevent::EnableTCPFastOpen() {
373 if (!use_tcp_fastopen_ && IsTCPFastOpenSupported()) {
374 use_tcp_fastopen_ = true;
375 }
mmenke 2014/08/12 15:25:16 nit: There's a preference not to use braces for s
Jana 2014/08/13 07:33:40 Done.
376 }
377
372 bool TCPSocketLibevent::IsValid() const { 378 bool TCPSocketLibevent::IsValid() const {
373 return socket_ != NULL && socket_->socket_fd() != kInvalidSocket; 379 return socket_ != NULL && socket_->socket_fd() != kInvalidSocket;
374 } 380 }
375 381
376 void TCPSocketLibevent::StartLoggingMultipleConnectAttempts( 382 void TCPSocketLibevent::StartLoggingMultipleConnectAttempts(
377 const AddressList& addresses) { 383 const AddressList& addresses) {
378 if (!logging_multiple_connect_attempts_) { 384 if (!logging_multiple_connect_attempts_) {
379 logging_multiple_connect_attempts_ = true; 385 logging_multiple_connect_attempts_ = true;
380 LogConnectBegin(addresses); 386 LogConnectBegin(addresses);
381 } else { 387 } else {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 494
489 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT, 495 net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT,
490 CreateNetLogSourceAddressCallback(storage.addr, 496 CreateNetLogSourceAddressCallback(storage.addr,
491 storage.addr_len)); 497 storage.addr_len));
492 } 498 }
493 499
494 void TCPSocketLibevent::ReadCompleted(const scoped_refptr<IOBuffer>& buf, 500 void TCPSocketLibevent::ReadCompleted(const scoped_refptr<IOBuffer>& buf,
495 const CompletionCallback& callback, 501 const CompletionCallback& callback,
496 int rv) { 502 int rv) {
497 DCHECK_NE(ERR_IO_PENDING, rv); 503 DCHECK_NE(ERR_IO_PENDING, rv);
498 // Records fast open status regardless of error in asynchronous case. 504 // Records fastopen status regardless of error in asynchronous case.
mmenke 2014/08/12 15:25:16 nit: Maybe capitalize, too?
499 // TODO(rdsmith,jri): Change histogram name to indicate it could be called on 505 // TODO(rdsmith,jri): Change histogram name to indicate it could be called on
500 // error. 506 // error.
501 RecordFastOpenStatus(); 507 RecordFastOpenStatus();
502 callback.Run(HandleReadCompleted(buf, rv)); 508 callback.Run(HandleReadCompleted(buf, rv));
503 } 509 }
504 510
505 int TCPSocketLibevent::HandleReadCompleted(IOBuffer* buf, int rv) { 511 int TCPSocketLibevent::HandleReadCompleted(IOBuffer* buf, int rv) {
506 if (rv < 0) { 512 if (rv < 0) {
507 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, 513 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR,
508 CreateNetLogSocketErrorCallback(rv, errno)); 514 CreateNetLogSocketErrorCallback(rv, errno));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 } 596 }
591 597
592 void TCPSocketLibevent::RecordFastOpenStatus() { 598 void TCPSocketLibevent::RecordFastOpenStatus() {
593 if (use_tcp_fastopen_ && 599 if (use_tcp_fastopen_ &&
594 (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN || 600 (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN ||
595 fast_open_status_ == FAST_OPEN_SLOW_CONNECT_RETURN)) { 601 fast_open_status_ == FAST_OPEN_SLOW_CONNECT_RETURN)) {
596 DCHECK_NE(FAST_OPEN_STATUS_UNKNOWN, fast_open_status_); 602 DCHECK_NE(FAST_OPEN_STATUS_UNKNOWN, fast_open_status_);
597 bool getsockopt_success(false); 603 bool getsockopt_success(false);
598 bool server_acked_data(false); 604 bool server_acked_data(false);
599 #if defined(TCP_INFO) 605 #if defined(TCP_INFO)
600 // Probe to see the if the socket used TCP Fast Open. 606 // Probe to see the if the socket used TCP FastOpen.
601 tcp_info info; 607 tcp_info info;
602 socklen_t info_len = sizeof(tcp_info); 608 socklen_t info_len = sizeof(tcp_info);
603 getsockopt_success = 609 getsockopt_success =
604 getsockopt(socket_->socket_fd(), IPPROTO_TCP, TCP_INFO, 610 getsockopt(socket_->socket_fd(), IPPROTO_TCP, TCP_INFO,
605 &info, &info_len) == 0 && 611 &info, &info_len) == 0 &&
606 info_len == sizeof(tcp_info); 612 info_len == sizeof(tcp_info);
607 server_acked_data = getsockopt_success && 613 server_acked_data = getsockopt_success &&
608 (info.tcpi_options & TCPI_OPT_SYN_DATA); 614 (info.tcpi_options & TCPI_OPT_SYN_DATA);
609 #endif 615 #endif
610 if (getsockopt_success) { 616 if (getsockopt_success) {
611 if (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN) { 617 if (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN) {
612 fast_open_status_ = (server_acked_data ? FAST_OPEN_SYN_DATA_ACK : 618 fast_open_status_ = (server_acked_data ? FAST_OPEN_SYN_DATA_ACK :
613 FAST_OPEN_SYN_DATA_NACK); 619 FAST_OPEN_SYN_DATA_NACK);
614 } else { 620 } else {
615 fast_open_status_ = (server_acked_data ? FAST_OPEN_NO_SYN_DATA_ACK : 621 fast_open_status_ = (server_acked_data ? FAST_OPEN_NO_SYN_DATA_ACK :
616 FAST_OPEN_NO_SYN_DATA_NACK); 622 FAST_OPEN_NO_SYN_DATA_NACK);
617 } 623 }
618 } else { 624 } else {
619 fast_open_status_ = (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN ? 625 fast_open_status_ = (fast_open_status_ == FAST_OPEN_FAST_CONNECT_RETURN ?
620 FAST_OPEN_SYN_DATA_FAILED : 626 FAST_OPEN_SYN_DATA_FAILED :
621 FAST_OPEN_NO_SYN_DATA_FAILED); 627 FAST_OPEN_NO_SYN_DATA_FAILED);
622 } 628 }
623 } 629 }
624 } 630 }
625
626 } // namespace net 631 } // namespace net
mmenke 2014/08/12 15:25:16 nit: keep the blank line before the end of the na
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698