blob: cdfadb52f8120f819521d20ff69841a347db848d [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2011 The Chromium Authors
[email protected]a2798d92011-03-02 22:56:182// 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_UDP_CLIENT_SOCKET_H_
6#define NET_SOCKET_UDP_CLIENT_SOCKET_H_
[email protected]a2798d92011-03-02 22:56:187
tfarinac40df1c2015-11-30 22:31:478#include <stdint.h>
9
bnc81c46c1f2016-10-04 16:25:5910#include "net/base/net_export.h"
tfarina5dd13c22016-11-16 12:08:2611#include "net/socket/datagram_client_socket.h"
12#include "net/socket/udp_socket.h"
[email protected]a2b2cfc2017-12-06 09:06:0813#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]a2798d92011-03-02 22:56:1814
15namespace net {
16
mikecironef22f9812016-10-04 03:40:1917class NetLog;
18struct NetLogSource;
[email protected]a2798d92011-03-02 22:56:1819
20// A client socket that uses UDP as the transport layer.
[email protected]172da1b2011-08-12 15:52:2621class NET_EXPORT_PRIVATE UDPClientSocket : public DatagramClientSocket {
[email protected]a2798d92011-03-02 22:56:1822 public:
Stefano Duoa44b1192022-01-25 15:24:5923 // If `network` is specified, the socket will be bound to it. All data traffic
24 // on the socket will be sent and received via `network`. Communication using
25 // this socket will fail if `network` disconnects.
Stefano Duo6527ed42022-07-29 09:25:4426 UDPClientSocket(
27 DatagramSocket::BindType bind_type,
28 net::NetLog* net_log,
29 const net::NetLogSource& source,
30 handles::NetworkHandle network = handles::kInvalidNetworkHandle);
Peter Boström293b1342021-09-22 17:31:4331
32 UDPClientSocket(const UDPClientSocket&) = delete;
33 UDPClientSocket& operator=(const UDPClientSocket&) = delete;
34
dchengb03027d2014-10-21 12:00:2035 ~UDPClientSocket() override;
[email protected]a2798d92011-03-02 22:56:1836
[email protected]3f55aa12011-12-07 02:03:3337 // DatagramClientSocket implementation.
dchengb03027d2014-10-21 12:00:2038 int Connect(const IPEndPoint& address) override;
Stefano Duo6527ed42022-07-29 09:25:4439 int ConnectUsingNetwork(handles::NetworkHandle network,
jrid2489452016-03-31 22:42:0840 const IPEndPoint& address) override;
41 int ConnectUsingDefaultNetwork(const IPEndPoint& address) override;
Liza Burakova892ce1c2022-09-19 16:44:4642 int ConnectAsync(const IPEndPoint& address,
43 CompletionOnceCallback callback) override;
44 int ConnectUsingNetworkAsync(handles::NetworkHandle network,
45 const IPEndPoint& address,
46 CompletionOnceCallback callback) override;
47 int ConnectUsingDefaultNetworkAsync(const IPEndPoint& address,
48 CompletionOnceCallback callback) override;
49
Stefano Duo6527ed42022-07-29 09:25:4450 handles::NetworkHandle GetBoundNetwork() const override;
Paul Jensen0f49dec2017-12-12 23:39:5851 void ApplySocketTag(const SocketTag& tag) override;
dchengb03027d2014-10-21 12:00:2052 int Read(IOBuffer* buf,
53 int buf_len,
Brad Lassey3a814172018-04-26 03:30:2154 CompletionOnceCallback callback) override;
dchengb03027d2014-10-21 12:00:2055 int Write(IOBuffer* buf,
56 int buf_len,
Brad Lassey3a814172018-04-26 03:30:2157 CompletionOnceCallback callback,
[email protected]578968d42017-12-13 15:39:3258 const NetworkTrafficAnnotationTag& traffic_annotation) override;
Charles 'Buck' Krasic762317f2018-03-30 20:08:0959
dchengb03027d2014-10-21 12:00:2060 void Close() override;
61 int GetPeerAddress(IPEndPoint* address) const override;
62 int GetLocalAddress(IPEndPoint* address) const override;
Charles 'Buck' Krasic762317f2018-03-30 20:08:0963 // Switch to use non-blocking IO. Must be called right after construction and
64 // before other calls.
rcha7c65922016-08-18 13:49:0865 void UseNonBlockingIO() override;
tfarinac40df1c2015-11-30 22:31:4766 int SetReceiveBufferSize(int32_t size) override;
67 int SetSendBufferSize(int32_t size) override;
rchff006a12016-08-24 23:56:3168 int SetDoNotFragment() override;
Yixin Wang3ae76ca2018-03-15 17:18:5269 void SetMsgConfirm(bool confirm) override;
tfarina428341112016-09-22 13:38:2070 const NetLogWithSource& NetLog() const override;
kapishnikov7f8dd1e2018-01-24 06:10:4971 void EnableRecvOptimization() override;
[email protected]a2798d92011-03-02 22:56:1872
Qingsi Wangeb994032019-01-11 02:36:1473 int SetMulticastInterface(uint32_t interface_index) override;
Yu Suca37f3c2020-10-09 20:02:2374 void SetIOSNetworkServiceType(int ios_network_service_type) override;
Nidhi Jaju6f46e082022-12-14 09:09:2075 void SetDontClose(bool dont_close) override;
Charles 'Buck' Krasic762317f2018-03-30 20:08:0976
[email protected]a2798d92011-03-02 22:56:1877 private:
78 UDPSocket socket_;
Stefano Duoa44b1192022-01-25 15:24:5979 // The network the socket is currently bound to.
Stefano Duo6527ed42022-07-29 09:25:4480 handles::NetworkHandle network_;
81 handles::NetworkHandle connect_using_network_;
[email protected]a2798d92011-03-02 22:56:1882};
83
84} // namespace net
85
86#endif // NET_SOCKET_UDP_CLIENT_SOCKET_H_