Java Code Examples for android.system.Os#pipe()

The following examples show how to use android.system.Os#pipe() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileUtils.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private MemoryPipe(byte[] data, boolean sink) throws IOException {
    try {
        this.pipe = Os.pipe();
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
    this.data = data;
    this.sink = sink;
}
 
Example 2
Source File: ParcelFileDescriptor.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 {
    try {
        final FileDescriptor[] fds = Os.pipe();
        return new ParcelFileDescriptor[] {
                new ParcelFileDescriptor(fds[0]),
                new ParcelFileDescriptor(fds[1]) };
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
 
Example 3
Source File: ParcelFileDescriptor.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 * <p>
 * The write end has the ability to deliver an error message through
 * {@link #closeWithError(String)} which can be handled by the read end
 * calling {@link #checkError()}, usually after detecting an EOF.
 * This can also be used to detect remote crashes.
 */
public static ParcelFileDescriptor[] createReliablePipe() throws IOException {
    try {
        final FileDescriptor[] comm = createCommSocketPair();
        final FileDescriptor[] fds = Os.pipe();
        return new ParcelFileDescriptor[] {
                new ParcelFileDescriptor(fds[0], comm[0]),
                new ParcelFileDescriptor(fds[1], comm[1]) };
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
 
Example 4
Source File: HttpsProvider.java    From Daedalus with GNU General Public License v3.0 4 votes vote down vote up
public void process() {
    try {
        FileDescriptor[] pipes = Os.pipe();
        mInterruptFd = pipes[0];
        mBlockFd = pipes[1];
        FileInputStream inputStream = new FileInputStream(descriptor.getFileDescriptor());
        FileOutputStream outputStream = new FileOutputStream(descriptor.getFileDescriptor());

        byte[] packet = new byte[32767];
        while (running) {
            StructPollfd deviceFd = new StructPollfd();
            deviceFd.fd = inputStream.getFD();
            deviceFd.events = (short) OsConstants.POLLIN;
            StructPollfd blockFd = new StructPollfd();
            blockFd.fd = mBlockFd;
            blockFd.events = (short) (OsConstants.POLLHUP | OsConstants.POLLERR);

            if (!deviceWrites.isEmpty())
                deviceFd.events |= (short) OsConstants.POLLOUT;

            StructPollfd[] polls = new StructPollfd[2];
            polls[0] = deviceFd;
            polls[1] = blockFd;
            Os.poll(polls, 100);
            if (blockFd.revents != 0) {
                Log.i(TAG, "Told to stop VPN");
                running = false;
                return;
            }

            Iterator<WaitingHttpsRequest> iterator = whqList.iterator();
            while (iterator.hasNext()) {
                WaitingHttpsRequest request = iterator.next();
                if (request.completed) {
                    handleDnsResponse(request.packet, request.result);
                    iterator.remove();
                }
            }

            if ((deviceFd.revents & OsConstants.POLLOUT) != 0) {
                Log.d(TAG, "Write to device");
                writeToDevice(outputStream);
            }
            if ((deviceFd.revents & OsConstants.POLLIN) != 0) {
                Log.d(TAG, "Read from device");
                readPacketFromDevice(inputStream, packet);
            }
            service.providerLoopCallback();
        }
    } catch (Exception e) {
        Logger.logException(e);
    }
}