| OLD | NEW |
| 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 #ifndef NET_SOCKET_TCP_SOCKET_H_ | 5 #ifndef NET_SOCKET_TCP_SOCKET_H_ |
| 6 #define NET_SOCKET_TCP_SOCKET_H_ | 6 #define NET_SOCKET_TCP_SOCKET_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "net/base/net_export.h" | 9 #include "net/base/net_export.h" |
| 10 #include "net/socket/socket_descriptor.h" | |
| 11 | 10 |
| 12 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 13 #include "net/socket/tcp_socket_win.h" | 12 #include "net/socket/tcp_socket_win.h" |
| 14 #elif defined(OS_POSIX) | 13 #elif defined(OS_POSIX) |
| 15 #include "net/socket/tcp_socket_posix.h" | 14 #include "net/socket/tcp_socket_posix.h" |
| 16 #endif | 15 #endif |
| 17 | 16 |
| 18 namespace net { | 17 namespace net { |
| 19 | 18 |
| 20 // TCPSocket provides a platform-independent interface for TCP sockets. | 19 // TCPSocket provides a platform-independent interface for TCP sockets. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 bool IsTCPFastOpenSupported(); | 32 bool IsTCPFastOpenSupported(); |
| 34 | 33 |
| 35 // Check if TCP FastOpen is enabled by the user. | 34 // Check if TCP FastOpen is enabled by the user. |
| 36 bool IsTCPFastOpenUserEnabled(); | 35 bool IsTCPFastOpenUserEnabled(); |
| 37 | 36 |
| 38 // Checks if TCP FastOpen is supported by the kernel. Also enables TFO for all | 37 // Checks if TCP FastOpen is supported by the kernel. Also enables TFO for all |
| 39 // connections if indicated by user. | 38 // connections if indicated by user. |
| 40 // Not thread safe. Must be called during initialization/startup only. | 39 // Not thread safe. Must be called during initialization/startup only. |
| 41 NET_EXPORT void CheckSupportAndMaybeEnableTCPFastOpen(bool user_enabled); | 40 NET_EXPORT void CheckSupportAndMaybeEnableTCPFastOpen(bool user_enabled); |
| 42 | 41 |
| 43 // This function enables/disables buffering in the kernel. By default, on Linux, | |
| 44 // TCP sockets will wait up to 200ms for more data to complete a packet before | |
| 45 // transmitting. After calling this function, the kernel will not wait. See | |
| 46 // TCP_NODELAY in `man 7 tcp`. | |
| 47 // | |
| 48 // For Windows: | |
| 49 // | |
| 50 // The Nagle implementation on Windows is governed by RFC 896. The idea | |
| 51 // behind Nagle is to reduce small packets on the network. When Nagle is | |
| 52 // enabled, if a partial packet has been sent, the TCP stack will disallow | |
| 53 // further *partial* packets until an ACK has been received from the other | |
| 54 // side. Good applications should always strive to send as much data as | |
| 55 // possible and avoid partial-packet sends. However, in most real world | |
| 56 // applications, there are edge cases where this does not happen, and two | |
| 57 // partial packets may be sent back to back. For a browser, it is NEVER | |
| 58 // a benefit to delay for an RTT before the second packet is sent. | |
| 59 // | |
| 60 // As a practical example in Chromium today, consider the case of a small | |
| 61 // POST. I have verified this: | |
| 62 // Client writes 649 bytes of header (partial packet #1) | |
| 63 // Client writes 50 bytes of POST data (partial packet #2) | |
| 64 // In the above example, with Nagle, a RTT delay is inserted between these | |
| 65 // two sends due to nagle. RTTs can easily be 100ms or more. The best | |
| 66 // fix is to make sure that for POSTing data, we write as much data as | |
| 67 // possible and minimize partial packets. We will fix that. But disabling | |
| 68 // Nagle also ensure we don't run into this delay in other edge cases. | |
| 69 // See also: | |
| 70 // http://technet.microsoft.com/en-us/library/bb726981.aspx | |
| 71 // | |
| 72 // This function returns true if it succeeds to set the TCP_NODELAY option, | |
| 73 // otherwise returns false. | |
| 74 NET_EXPORT_PRIVATE bool SetTCPNoDelay(SocketDescriptor socket, bool no_delay); | |
| 75 | |
| 76 } // namespace net | 42 } // namespace net |
| 77 | 43 |
| 78 #endif // NET_SOCKET_TCP_SOCKET_H_ | 44 #endif // NET_SOCKET_TCP_SOCKET_H_ |
| OLD | NEW |