ParcelFileDescriptor.FromDatagramSocket(DatagramSocket) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Create a new ParcelFileDescriptor from the specified DatagramSocket.
[Android.Runtime.Register("fromDatagramSocket", "(Ljava/net/DatagramSocket;)Landroid/os/ParcelFileDescriptor;", "")]
public static Android.OS.ParcelFileDescriptor? FromDatagramSocket (Java.Net.DatagramSocket? datagramSocket);
[<Android.Runtime.Register("fromDatagramSocket", "(Ljava/net/DatagramSocket;)Landroid/os/ParcelFileDescriptor;", "")>]
static member FromDatagramSocket : Java.Net.DatagramSocket -> Android.OS.ParcelFileDescriptor
Parameters
- datagramSocket
- DatagramSocket
The DatagramSocket whose FileDescriptor is used to create a new ParcelFileDescriptor.
Returns
A new ParcelFileDescriptor with a duped copy of the FileDescriptor of the specified Socket.
- Attributes
Remarks
Create a new ParcelFileDescriptor from the specified DatagramSocket. The new ParcelFileDescriptor holds a dup of the original FileDescriptor in the DatagramSocket, so you must still close the DatagramSocket as well as the new ParcelFileDescriptor.
<strong>WARNING:</strong> Prior to API level 29, this function would not actually dup the DatagramSocket's FileDescriptor, and would take a reference to the its internal FileDescriptor instead. If the DatagramSocket gets garbage collected before the ParcelFileDescriptor, this may lead to the ParcelFileDescriptor being unexpectedly closed. To avoid this, the following pattern can be used:
{@code
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromDatagramSocket(socket).dup();
}
Java documentation for android.os.ParcelFileDescriptor.fromDatagramSocket(java.net.DatagramSocket)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.