xref: /aosp_15_r20/external/cronet/net/socket/transport_client_socket.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 The Chromium Authors
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 
8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_export.h"
10 #include "net/socket/connection_attempts.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.
17 class NET_EXPORT TransportClientSocket : public StreamSocket {
18  public:
19   TransportClientSocket();
20 
21   TransportClientSocket(const TransportClientSocket&) = delete;
22   TransportClientSocket& operator=(const TransportClientSocket&) = delete;
23 
24   ~TransportClientSocket() override;
25 
26   // Binds the socket to a local address, |local_addr|. Returns OK on success,
27   // and a net error code on failure.
28   virtual int Bind(const net::IPEndPoint& local_addr) = 0;
29 
30   // Enables/disables buffering in the kernel. By default, on Linux, TCP sockets
31   // will wait up to 200ms for more data to complete a packet before
32   // transmitting. After calling this function, the kernel will not wait. See
33   // TCP_NODELAY in `man 7 tcp`. On Windows, the Nagle implementation is
34   // governed by RFC 896. SetTCPNoDelay() sets the TCP_NODELAY option. Use
35   // |no_delay| to enable or disable it. Returns true on success, and false on
36   // failure.
37   //
38   // Should not be called and will always fail until there is not an underlying
39   // platform socket ready to receive options. The underlying platform socket
40   // should always be ready after successful connection or slightly earlier
41   // during BeforeConnect handlers.
42   virtual bool SetNoDelay(bool no_delay);
43 
44   // Enables or disables TCP Keep-Alive (which is the SO_KEEPALIVE option on the
45   // socket). The unit for the delay is in seconds. Returns true on success, and
46   // false on failure.
47   //
48   // Should not be called and will always fail until there is not an underlying
49   // platform socket ready to receive options. The underlying platform socket
50   // should always be ready after successful connection or slightly earlier
51   // during BeforeConnect handlers.
52   virtual bool SetKeepAlive(bool enable, int delay_secs);
53 };
54 
55 }  // namespace net
56 
57 #endif  // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_H_
58