udp_client_socket.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (c) 2011 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. #ifndef NET_SOCKET_UDP_CLIENT_SOCKET_H_
  5. #define NET_SOCKET_UDP_CLIENT_SOCKET_H_
  6. #include <stdint.h>
  7. #include "net/base/net_export.h"
  8. #include "net/socket/datagram_client_socket.h"
  9. #include "net/socket/udp_socket.h"
  10. #include "net/traffic_annotation/network_traffic_annotation.h"
  11. namespace net {
  12. class NetLog;
  13. struct NetLogSource;
  14. // A client socket that uses UDP as the transport layer.
  15. class NET_EXPORT_PRIVATE UDPClientSocket : public DatagramClientSocket {
  16. public:
  17. // If `network` is specified, the socket will be bound to it. All data traffic
  18. // on the socket will be sent and received via `network`. Communication using
  19. // this socket will fail if `network` disconnects.
  20. UDPClientSocket(
  21. DatagramSocket::BindType bind_type,
  22. net::NetLog* net_log,
  23. const net::NetLogSource& source,
  24. handles::NetworkHandle network = handles::kInvalidNetworkHandle);
  25. UDPClientSocket(const UDPClientSocket&) = delete;
  26. UDPClientSocket& operator=(const UDPClientSocket&) = delete;
  27. ~UDPClientSocket() override;
  28. // DatagramClientSocket implementation.
  29. int Connect(const IPEndPoint& address) override;
  30. int ConnectUsingNetwork(handles::NetworkHandle network,
  31. const IPEndPoint& address) override;
  32. int ConnectUsingDefaultNetwork(const IPEndPoint& address) override;
  33. handles::NetworkHandle GetBoundNetwork() const override;
  34. void ApplySocketTag(const SocketTag& tag) override;
  35. int Read(IOBuffer* buf,
  36. int buf_len,
  37. CompletionOnceCallback callback) override;
  38. int Write(IOBuffer* buf,
  39. int buf_len,
  40. CompletionOnceCallback callback,
  41. const NetworkTrafficAnnotationTag& traffic_annotation) override;
  42. void Close() override;
  43. int GetPeerAddress(IPEndPoint* address) const override;
  44. int GetLocalAddress(IPEndPoint* address) const override;
  45. // Switch to use non-blocking IO. Must be called right after construction and
  46. // before other calls.
  47. void UseNonBlockingIO() override;
  48. int SetReceiveBufferSize(int32_t size) override;
  49. int SetSendBufferSize(int32_t size) override;
  50. int SetDoNotFragment() override;
  51. void SetMsgConfirm(bool confirm) override;
  52. const NetLogWithSource& NetLog() const override;
  53. void EnableRecvOptimization() override;
  54. int SetMulticastInterface(uint32_t interface_index) override;
  55. void SetIOSNetworkServiceType(int ios_network_service_type) override;
  56. private:
  57. UDPSocket socket_;
  58. // The network the socket is currently bound to.
  59. handles::NetworkHandle network_;
  60. handles::NetworkHandle connect_using_network_;
  61. };
  62. } // namespace net
  63. #endif // NET_SOCKET_UDP_CLIENT_SOCKET_H_