Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_SOCKET_TRANSPORT_CLIENT_SOCKET_H_ |
| 6 | #define NET_SOCKET_TRANSPORT_CLIENT_SOCKET_H_ |
| 7 | |
Helen Li | 48f117e | 2018-05-29 20:38:40 | [diff] [blame] | 8 | #include "base/macros.h" |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 9 | #include "net/base/ip_endpoint.h" |
| 10 | #include "net/base/net_export.h" |
| 11 | #include "net/socket/stream_socket.h" |
| 12 | |
| 13 | namespace net { |
| 14 | |
| 15 | // A socket class that extends StreamSocket to provide methods that are relevant |
| 16 | // to a transport client socket. |
Helen Li | 48f117e | 2018-05-29 20:38:40 | [diff] [blame] | 17 | class NET_EXPORT TransportClientSocket : public StreamSocket { |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 18 | public: |
Helen Li | 48f117e | 2018-05-29 20:38:40 | [diff] [blame] | 19 | TransportClientSocket(); |
| 20 | ~TransportClientSocket() override; |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 21 | |
| 22 | // Binds the socket to a local address, |local_addr|. Returns OK on success, |
| 23 | // and a net error code on failure. |
| 24 | virtual int Bind(const net::IPEndPoint& local_addr) = 0; |
Helen Li | 48f117e | 2018-05-29 20:38:40 | [diff] [blame] | 25 | |
| 26 | // Enables/disables buffering in the kernel. By default, on Linux, TCP sockets |
| 27 | // will wait up to 200ms for more data to complete a packet before |
| 28 | // transmitting. After calling this function, the kernel will not wait. See |
| 29 | // TCP_NODELAY in `man 7 tcp`. On Windows, the Nagle implementation is |
| 30 | // governed by RFC 896. SetTCPNoDelay() sets the TCP_NODELAY option. Use |
| 31 | // |no_delay| to enable or disable it. Returns true on success, and false on |
| 32 | // failure. |
Eric Orth | bb24dfc | 2020-02-11 00:51:17 | [diff] [blame] | 33 | // |
| 34 | // Should not be called and will always fail until there is not an underlying |
| 35 | // platform socket ready to receive options. The underlying platform socket |
| 36 | // should always be ready after successful connection or slightly earlier |
| 37 | // during BeforeConnect handlers. |
Helen Li | 48f117e | 2018-05-29 20:38:40 | [diff] [blame] | 38 | virtual bool SetNoDelay(bool no_delay); |
| 39 | |
| 40 | // Enables or disables TCP Keep-Alive (which is the SO_KEEPALIVE option on the |
| 41 | // socket). The unit for the delay is in seconds. Returns true on success, and |
| 42 | // false on failure. |
Eric Orth | bb24dfc | 2020-02-11 00:51:17 | [diff] [blame] | 43 | // |
| 44 | // Should not be called and will always fail until there is not an underlying |
| 45 | // platform socket ready to receive options. The underlying platform socket |
| 46 | // should always be ready after successful connection or slightly earlier |
| 47 | // during BeforeConnect handlers. |
Helen Li | 48f117e | 2018-05-29 20:38:40 | [diff] [blame] | 48 | virtual bool SetKeepAlive(bool enable, int delay_secs); |
| 49 | |
| 50 | private: |
| 51 | DISALLOW_COPY_AND_ASSIGN(TransportClientSocket); |
Helen Li | d5bb922 | 2018-04-12 15:33:09 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | } // namespace net |
| 55 | |
| 56 | #endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_H_ |