Commit 6f7c97a7 by claincly Committed by kim-vde

Add method to expose the locally opened port for UdpDataSource.

PiperOrigin-RevId: 341707809
parent b1eef00b
...@@ -45,6 +45,8 @@ public final class UdpDataSource extends BaseDataSource { ...@@ -45,6 +45,8 @@ public final class UdpDataSource extends BaseDataSource {
/** The default socket timeout, in milliseconds. */ /** The default socket timeout, in milliseconds. */
public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS = 8 * 1000; public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS = 8 * 1000;
public static final int UDP_PORT_UNSET = -1;
private final int socketTimeoutMillis; private final int socketTimeoutMillis;
private final byte[] packetBuffer; private final byte[] packetBuffer;
private final DatagramPacket packet; private final DatagramPacket packet;
...@@ -169,4 +171,15 @@ public final class UdpDataSource extends BaseDataSource { ...@@ -169,4 +171,15 @@ public final class UdpDataSource extends BaseDataSource {
transferEnded(); transferEnded();
} }
} }
/**
* Returns the local port number opened for the UDP connection, or {@link #UDP_PORT_UNSET} if no
* connection is open
*/
public int getLocalPort() {
if (socket == null) {
return UDP_PORT_UNSET;
}
return socket.getLocalPort();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment