diff --git a/src/org/ice4j/socket/GoogleRelayedCandidateDelegate.java b/src/org/ice4j/socket/GoogleRelayedCandidateDelegate.java index 4e2d380..3a100c9 100644 --- a/src/org/ice4j/socket/GoogleRelayedCandidateDelegate.java +++ b/src/org/ice4j/socket/GoogleRelayedCandidateDelegate.java @@ -362,7 +362,6 @@ public class GoogleRelayedCandidateDelegate else { packetsToSend.add(MultiplexingDatagramSocket.clone(p)); - if (sendThread == null) createSendThread(); else diff --git a/src/org/ice4j/socket/MultiplexingDatagramSocket.java b/src/org/ice4j/socket/MultiplexingDatagramSocket.java index a3a41ce..b84bfbf 100644 --- a/src/org/ice4j/socket/MultiplexingDatagramSocket.java +++ b/src/org/ice4j/socket/MultiplexingDatagramSocket.java @@ -50,6 +50,25 @@ public class MultiplexingDatagramSocket * specified DatagramPacket */ public static DatagramPacket clone(DatagramPacket p) + { + return clone(p, /* arraycopy */ true); + } + + /** + * Initializes a new DatagramPacket instance which is a clone of a + * specific DatagramPacket i.e. the properties of the clone + * DatagramPacket are clones of the specified + * DatagramPacket. + * + * @param p the DatagramPacket to clone + * @param arraycopy true if the actual bytes of the data of + * p are to be copied into the clone or false if only the + * capacity of the data of p is to be cloned without copying the + * actual bytes of the data of p + * @return a new DatagramPacket instance which is a clone of the + * specified DatagramPacket + */ + public static DatagramPacket clone(DatagramPacket p, boolean arraycopy) { byte[] data; int off; @@ -71,7 +90,7 @@ public class MultiplexingDatagramSocket // However, only copy the range of data starting with off and // spanning len number of bytes. Of course, preserve off and len // in addition to the capacity. - if (len > 0) + if (arraycopy && (len > 0)) { int arraycopyOff, arraycopyLen; @@ -582,7 +601,7 @@ public class MultiplexingDatagramSocket } // The caller will receive from the network. - DatagramPacket c = clone(p); + DatagramPacket c = clone(p, /* arraycopy */ false); synchronized (receiveSyncRoot) { @@ -614,7 +633,10 @@ public class MultiplexingDatagramSocket { synchronized (socket.received) { - socket.received.add(accepted ? clone(c) : c); + socket.received.add( + accepted + ? clone(c, /* arraycopy */ true) + : c); socket.received.notifyAll(); } accepted = true; diff --git a/src/org/ice4j/socket/RelayedCandidateDatagramSocket.java b/src/org/ice4j/socket/RelayedCandidateDatagramSocket.java index 68191d1..cc37af6 100644 --- a/src/org/ice4j/socket/RelayedCandidateDatagramSocket.java +++ b/src/org/ice4j/socket/RelayedCandidateDatagramSocket.java @@ -1063,7 +1063,6 @@ public class RelayedCandidateDatagramSocket else { packetsToSend.add(MultiplexingDatagramSocket.clone(p)); - if (sendThread == null) createSendThread(); else