diff --git a/api/src/main/java/com/sedmelluq/discord/lavaplayer/udpqueue/natives/UdpQueueManager.java b/api/src/main/java/com/sedmelluq/discord/lavaplayer/udpqueue/natives/UdpQueueManager.java index 4062548..55bc394 100644 --- a/api/src/main/java/com/sedmelluq/discord/lavaplayer/udpqueue/natives/UdpQueueManager.java +++ b/api/src/main/java/com/sedmelluq/discord/lavaplayer/udpqueue/natives/UdpQueueManager.java @@ -57,6 +57,7 @@ public int getCapacity() { * * @param key Unique queue identifier * @param packet Packet to add to the queue + * @param address The remote socket address * @return True if adding the packet to the queue succeeded */ public boolean queuePacket(long key, ByteBuffer packet, InetSocketAddress address) { @@ -75,6 +76,33 @@ public boolean queuePacket(long key, ByteBuffer packet, InetSocketAddress addres } } + /** + * Adds one packet to the specified queue that will be sent with the specified socket. + * Will fail if the maximum size of the queue is reached. There is no need to manually create a queue, + * it is automatically created when the first packet is added to it and deleted when it becomes empty. + * + * @param key Unique queue identifier + * @param packet Packet to add to the queue + * @param address The remote socket address + * @param explicitSocket The socket file descriptor to use to send the packet + * @return True if adding the packet to the queue succeeded + */ + public boolean queuePacketWithSocket(long key, ByteBuffer packet, InetSocketAddress address, long explicitSocket) { + synchronized (library) { + if (released) { + return false; + } + + int length = packet.remaining(); + packetBuffer.clear(); + packetBuffer.put(packet); + + int port = address.getPort(); + String hostAddress = address.getAddress().getHostAddress(); + return library.queuePacketWithSocket(instance, key, hostAddress, port, packetBuffer, length, explicitSocket); + } + } + /** * This is the method that should be called to start processing the queues. It will use the current thread and return * only when close() method is called on the queue manager.