am 389a440a: Backport ParcelFileDescriptor.createPipe() from master.
Merge commit '389a440ad13f7b16e8f7c7f1670bdd55f1e2112a' into gingerbread-plus-aosp * commit '389a440ad13f7b16e8f7c7f1670bdd55f1e2112a': Backport ParcelFileDescriptor.createPipe() from master.
This commit is contained in:
@@ -128891,6 +128891,19 @@
|
|||||||
<exception name="IOException" type="java.io.IOException">
|
<exception name="IOException" type="java.io.IOException">
|
||||||
</exception>
|
</exception>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="createPipe"
|
||||||
|
return="android.os.ParcelFileDescriptor[]"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="true"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<exception name="IOException" type="java.io.IOException">
|
||||||
|
</exception>
|
||||||
|
</method>
|
||||||
<method name="describeContents"
|
<method name="describeContents"
|
||||||
return="int"
|
return="int"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
|
|||||||
@@ -133,6 +133,25 @@ public class ParcelFileDescriptor implements Parcelable {
|
|||||||
// Extracts the file descriptor from the specified socket and returns it untouched
|
// Extracts the file descriptor from the specified socket and returns it untouched
|
||||||
private static native FileDescriptor getFileDescriptorFromSocket(Socket socket);
|
private static native FileDescriptor getFileDescriptorFromSocket(Socket socket);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create two ParcelFileDescriptors structured as a data pipe. The first
|
||||||
|
* ParcelFileDescriptor in the returned array is the read side; the second
|
||||||
|
* is the write side.
|
||||||
|
*/
|
||||||
|
public static ParcelFileDescriptor[] createPipe() throws IOException {
|
||||||
|
FileDescriptor[] fds = new FileDescriptor[2];
|
||||||
|
int res = createPipeNative(fds);
|
||||||
|
if (res == 0) {
|
||||||
|
ParcelFileDescriptor[] pfds = new ParcelFileDescriptor[2];
|
||||||
|
pfds[0] = new ParcelFileDescriptor(fds[0]);
|
||||||
|
pfds[1] = new ParcelFileDescriptor(fds[1]);
|
||||||
|
return pfds;
|
||||||
|
}
|
||||||
|
throw new IOException("Unable to create pipe: errno=" + -res);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native int createPipeNative(FileDescriptor[] outFds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the actual FileDescriptor associated with this object.
|
* Retrieve the actual FileDescriptor associated with this object.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -66,6 +66,26 @@ static jobject android_os_ParcelFileDescriptor_getFileDescriptorFromSocket(JNIEn
|
|||||||
return fileDescriptorClone;
|
return fileDescriptorClone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int android_os_ParcelFileDescriptor_createPipeNative(JNIEnv* env,
|
||||||
|
jobject clazz, jobjectArray outFds)
|
||||||
|
{
|
||||||
|
int fds[2];
|
||||||
|
if (pipe(fds) < 0) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<2; i++) {
|
||||||
|
jobject fdObj = env->NewObject(gFileDescriptorOffsets.mClass,
|
||||||
|
gFileDescriptorOffsets.mConstructor);
|
||||||
|
if (fdObj != NULL) {
|
||||||
|
env->SetIntField(fdObj, gFileDescriptorOffsets.mDescriptor, fds[i]);
|
||||||
|
}
|
||||||
|
env->SetObjectArrayElement(outFds, i, fdObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static jint getFd(JNIEnv* env, jobject clazz)
|
static jint getFd(JNIEnv* env, jobject clazz)
|
||||||
{
|
{
|
||||||
jobject descriptor = env->GetObjectField(clazz, gParcelFileDescriptorOffsets.mFileDescriptor);
|
jobject descriptor = env->GetObjectField(clazz, gParcelFileDescriptorOffsets.mFileDescriptor);
|
||||||
@@ -109,6 +129,8 @@ static jlong android_os_ParcelFileDescriptor_seekTo(JNIEnv* env,
|
|||||||
static const JNINativeMethod gParcelFileDescriptorMethods[] = {
|
static const JNINativeMethod gParcelFileDescriptorMethods[] = {
|
||||||
{"getFileDescriptorFromSocket", "(Ljava/net/Socket;)Ljava/io/FileDescriptor;",
|
{"getFileDescriptorFromSocket", "(Ljava/net/Socket;)Ljava/io/FileDescriptor;",
|
||||||
(void*)android_os_ParcelFileDescriptor_getFileDescriptorFromSocket},
|
(void*)android_os_ParcelFileDescriptor_getFileDescriptorFromSocket},
|
||||||
|
{"createPipeNative", "([Ljava/io/FileDescriptor;)I",
|
||||||
|
(void*)android_os_ParcelFileDescriptor_createPipeNative},
|
||||||
{"getStatSize", "()J",
|
{"getStatSize", "()J",
|
||||||
(void*)android_os_ParcelFileDescriptor_getStatSize},
|
(void*)android_os_ParcelFileDescriptor_getStatSize},
|
||||||
{"seekTo", "(J)J",
|
{"seekTo", "(J)J",
|
||||||
|
|||||||
Reference in New Issue
Block a user