blob: 4f8c4b3fde1f7664a847dd3ee6ccccc76cb210dc [file] [log] [blame]
Helen Lid5bb9222018-04-12 15:33:091// 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 Li48f117e2018-05-29 20:38:408#include "base/macros.h"
Helen Lid5bb9222018-04-12 15:33:099#include "net/base/ip_endpoint.h"
10#include "net/base/net_export.h"
11#include "net/socket/stream_socket.h"
12
13namespace net {
14
15// A socket class that extends StreamSocket to provide methods that are relevant
16// to a transport client socket.
Helen Li48f117e2018-05-29 20:38:4017class NET_EXPORT TransportClientSocket : public StreamSocket {
Helen Lid5bb9222018-04-12 15:33:0918 public:
Helen Li48f117e2018-05-29 20:38:4019 TransportClientSocket();
20 ~TransportClientSocket() override;
Helen Lid5bb9222018-04-12 15:33:0921
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 Li48f117e2018-05-29 20:38:4025
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 Orthbb24dfc2020-02-11 00:51:1733 //
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 Li48f117e2018-05-29 20:38:4038 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 Orthbb24dfc2020-02-11 00:51:1743 //
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 Li48f117e2018-05-29 20:38:4048 virtual bool SetKeepAlive(bool enable, int delay_secs);
49
50 private:
51 DISALLOW_COPY_AND_ASSIGN(TransportClientSocket);
Helen Lid5bb9222018-04-12 15:33:0952};
53
54} // namespace net
55
56#endif // NET_SOCKET_TRANSPORT_CLIENT_SOCKET_H_