From c25c0915b553ac8e1cb37002626bb7d885587f81 Mon Sep 17 00:00:00 2001 From: boris Date: Tue, 5 Aug 2014 14:06:30 +0000 Subject: [PATCH] Adds a method that allows to check if there is a MultiplexedDatagramSocket for a particular DatagramPacketFilter. --- .../socket/MultiplexingDatagramSocket.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/org/ice4j/socket/MultiplexingDatagramSocket.java b/src/org/ice4j/socket/MultiplexingDatagramSocket.java index b52d401..ad0ff46 100644 --- a/src/org/ice4j/socket/MultiplexingDatagramSocket.java +++ b/src/org/ice4j/socket/MultiplexingDatagramSocket.java @@ -320,6 +320,32 @@ public class MultiplexingDatagramSocket * fails */ public MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter) + throws SocketException + { + return getSocket(filter, true); + } + + /** + * Gets a MultiplexedDatagramSocket which filters + * DatagramPackets away from this DatagramSocket using a + * specific DatagramPacketFilter. If create is true and + * such a MultiplexedDatagramSocket does not exist in this + * instance, it is created. + * + * @param filter the DatagramPacketFilter to get a + * MultiplexedDatagramSocket for + * @param create whether or not to create a MultiplexedDatagramSocket + * if this instance does not already have a socket for the given + * filter. + * @return a MultiplexedDatagramSocket which filters + * DatagramPackets away from this DatagramSocket using the + * specified filter + * @throws SocketException if creating the + * MultiplexedDatagramSocket for the specified filter + * fails. + */ + public MultiplexedDatagramSocket getSocket(DatagramPacketFilter filter, + boolean create) throws SocketException { if (filter == null) @@ -337,6 +363,9 @@ public class MultiplexingDatagramSocket return socket; } + if (!create) + return null; + // Create a new socket for the specified filter. MultiplexedDatagramSocket socket = new MultiplexedDatagramSocket(this, filter);