File: datagram_client_socket.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (104 lines) | stat: -rw-r--r-- 4,633 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_SOCKET_DATAGRAM_CLIENT_SOCKET_H_
#define NET_SOCKET_DATAGRAM_CLIENT_SOCKET_H_

#include "net/base/net_export.h"
#include "net/base/network_handle.h"
#include "net/socket/datagram_socket.h"
#include "net/socket/socket.h"

namespace net {

class IPEndPoint;
class SocketTag;

class NET_EXPORT_PRIVATE DatagramClientSocket : public DatagramSocket,
                                                public Socket {
 public:
  ~DatagramClientSocket() override = default;

  // Initialize this socket as a client socket to server at |address|. This
  // method can only be called once, as it opens a socket and socket reuse is
  // not supported. Returns a network error code.
  // TODO(liza): Remove this method once consumers have been updated.
  virtual int Connect(const IPEndPoint& address) = 0;

  // Binds this socket to |network| and initializes socket as a client socket
  // to server at |address|. All data traffic on the socket will be sent and
  // received via |network|. This call will fail if |network| has disconnected.
  // Communication using this socket will fail if |network| disconnects. Like
  // Connect, this method can only be called once. Returns a net error code.
  // TODO(liza): Remove this method once consumers have been updated.
  virtual int ConnectUsingNetwork(handles::NetworkHandle network,
                                  const IPEndPoint& address) = 0;

  // Same as ConnectUsingNetwork, except that the current default network is
  // used. Like Connect, this method can only be called once. Returns a net
  // error code.
  // TODO(liza): Remove this method once consumers have been updated.
  virtual int ConnectUsingDefaultNetwork(const IPEndPoint& address) = 0;

  // Same as Connect, but it can run asynchronously or synchronously. Returns a
  // network error code.
  // TODO(liza): Rename this to Connect once consumers have been updated.
  virtual int ConnectAsync(const IPEndPoint& address,
                           CompletionOnceCallback callback) = 0;

  // Same as ConnectUsingNetwork, but it can run asynchronously or
  // synchronously. Returns a network error code.
  // TODO(liza): Rename this to ConnectUsingNetwork once consumers have been
  // updated.
  virtual int ConnectUsingNetworkAsync(handles::NetworkHandle network,
                                       const IPEndPoint& address,
                                       CompletionOnceCallback callback) = 0;

  // Same as ConnectUsConnectUsingDefaultNetworkingNetwork, but it can run
  // asynchronously or synchronously. Returns a network error code.
  // TODO(liza): Rename this to ConnectUsingDefaultNetwork once consumers have
  // been updated.
  virtual int ConnectUsingDefaultNetworkAsync(
      const IPEndPoint& address,
      CompletionOnceCallback callback) = 0;

  // Returns the network that either ConnectUsingNetwork() or
  // ConnectUsingDefaultNetwork() bound this socket to. Returns
  // handles::kInvalidNetworkHandle if not explicitly bound via
  // ConnectUsingNetwork() or ConnectUsingDefaultNetwork().
  virtual handles::NetworkHandle GetBoundNetwork() const = 0;

  // Apply |tag| to this socket.
  virtual void ApplySocketTag(const SocketTag& tag) = 0;

  // Enables experimental optimization for receiving data from a socket.
  // By default, this method is no-op.
  virtual void EnableRecvOptimization() {}

  // Set interface to use for data sent to multicast groups. If
  // |interface_index| set to 0, default interface is used.
  // Must be called before Connect(), ConnectUsingNetwork() or
  // ConnectUsingDefaultNetwork().
  // Returns a network error code.
  virtual int SetMulticastInterface(uint32_t interface_index) = 0;

  // Set iOS Network Service Type for socket option SO_NET_SERVICE_TYPE.
  // No-op by default.
  virtual void SetIOSNetworkServiceType(int ios_network_service_type) {}

  // Register a QUIC UDP payload that can close a QUIC connection and the
  // underlying socket to the Android system server. When the app loses network
  // access, the system server destroys the registered socket and sends the
  // registered UDP payload to the server.
  virtual void RegisterQuicConnectionClosePayload(base::span<uint8_t> payload) {
  }

  // Unregister the underlying socket and its associated UDP payload that were
  // previously registered by RegisterQuicConnectionClosePayload
  virtual void UnregisterQuicConnectionClosePayload() {}
};

}  // namespace net

#endif  // NET_SOCKET_DATAGRAM_CLIENT_SOCKET_H_