1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef NET_DCSCTP_SOCKET_PACKET_SENDER_H_ 11 #define NET_DCSCTP_SOCKET_PACKET_SENDER_H_ 12 13 #include "net/dcsctp/packet/sctp_packet.h" 14 #include "net/dcsctp/public/dcsctp_socket.h" 15 16 namespace dcsctp { 17 18 // The PacketSender sends packets to the network using the provided callback 19 // interface. When an attempt to send a packet is made, the `on_sent_packet` 20 // callback will be triggered. 21 class PacketSender { 22 public: 23 PacketSender(DcSctpSocketCallbacks& callbacks, 24 std::function<void(rtc::ArrayView<const uint8_t>, 25 SendPacketStatus)> on_sent_packet); 26 27 // Sends the packet, and returns true if it was sent successfully. 28 bool Send(SctpPacket::Builder& builder); 29 30 private: 31 DcSctpSocketCallbacks& callbacks_; 32 33 // Callback that will be triggered for every send attempt, indicating the 34 // status of the operation. 35 std::function<void(rtc::ArrayView<const uint8_t>, SendPacketStatus)> 36 on_sent_packet_; 37 }; 38 } // namespace dcsctp 39 40 #endif // NET_DCSCTP_SOCKET_PACKET_SENDER_H_ 41