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

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

Issue 1728853006: net: merge two versions of SetTCPNoDelay() function into one (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: export it Created 4 years, 9 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
« no previous file with comments | « net/socket/tcp_socket.cc ('k') | net/socket/tcp_socket_win.cc » ('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 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 26 matching lines...) Expand all
37 namespace { 37 namespace {
38 38
39 // True if OS supports TCP FastOpen. 39 // True if OS supports TCP FastOpen.
40 bool g_tcp_fastopen_supported = false; 40 bool g_tcp_fastopen_supported = false;
41 // True if TCP FastOpen is user-enabled for all connections. 41 // True if TCP FastOpen is user-enabled for all connections.
42 // TODO(jri): Change global variable to param in HttpNetworkSession::Params. 42 // TODO(jri): Change global variable to param in HttpNetworkSession::Params.
43 bool g_tcp_fastopen_user_enabled = false; 43 bool g_tcp_fastopen_user_enabled = false;
44 // True if TCP FastOpen connect-with-write has failed at least once. 44 // True if TCP FastOpen connect-with-write has failed at least once.
45 bool g_tcp_fastopen_has_failed = false; 45 bool g_tcp_fastopen_has_failed = false;
46 46
47 // SetTCPNoDelay turns on/off buffering in the kernel. By default, TCP sockets
48 // will wait up to 200ms for more data to complete a packet before transmitting.
49 // After calling this function, the kernel will not wait. See TCP_NODELAY in
50 // `man 7 tcp`.
51 bool SetTCPNoDelay(int fd, bool no_delay) {
52 int on = no_delay ? 1 : 0;
53 int error = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
54 return error == 0;
55 }
56
57 // SetTCPKeepAlive sets SO_KEEPALIVE. 47 // SetTCPKeepAlive sets SO_KEEPALIVE.
58 bool SetTCPKeepAlive(int fd, bool enable, int delay) { 48 bool SetTCPKeepAlive(int fd, bool enable, int delay) {
59 // Enabling TCP keepalives is the same on all platforms. 49 // Enabling TCP keepalives is the same on all platforms.
60 int on = enable ? 1 : 0; 50 int on = enable ? 1 : 0;
61 if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on))) { 51 if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on))) {
62 PLOG(ERROR) << "Failed to set SO_KEEPALIVE on fd: " << fd; 52 PLOG(ERROR) << "Failed to set SO_KEEPALIVE on fd: " << fd;
63 return false; 53 return false;
64 } 54 }
65 55
66 // If we disabled TCP keep alive, our work is done here. 56 // If we disabled TCP keep alive, our work is done here.
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 if (info.tcpi_rtt > 0) { 753 if (info.tcpi_rtt > 0) {
764 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt); 754 *out_rtt = base::TimeDelta::FromMicroseconds(info.tcpi_rtt);
765 return true; 755 return true;
766 } 756 }
767 } 757 }
768 #endif // defined(TCP_INFO) 758 #endif // defined(TCP_INFO)
769 return false; 759 return false;
770 } 760 }
771 761
772 } // namespace net 762 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_socket.cc ('k') | net/socket/tcp_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698