Search in sources :

Example 1 with StructTimeval

use of libcore.io.StructTimeval in project android_frameworks_base by ParanoidAndroid.

the class NativeCrashListener method consumeNativeCrashData.

// Read the crash report from the debuggerd connection
void consumeNativeCrashData(FileDescriptor fd) {
    if (MORE_DEBUG)
        Slog.i(TAG, "debuggerd connected");
    final byte[] buf = new byte[4096];
    final ByteArrayOutputStream os = new ByteArrayOutputStream(4096);
    try {
        StructTimeval timeout = StructTimeval.fromMillis(SOCKET_TIMEOUT_MILLIS);
        Libcore.os.setsockoptTimeval(fd, SOL_SOCKET, SO_RCVTIMEO, timeout);
        Libcore.os.setsockoptTimeval(fd, SOL_SOCKET, SO_SNDTIMEO, timeout);
        // first, the pid and signal number
        int headerBytes = readExactly(fd, buf, 0, 8);
        if (headerBytes != 8) {
            // protocol failure; give up
            Slog.e(TAG, "Unable to read from debuggerd");
            return;
        }
        int pid = unpackInt(buf, 0);
        int signal = unpackInt(buf, 4);
        if (DEBUG) {
            Slog.v(TAG, "Read pid=" + pid + " signal=" + signal);
        }
        // now the text of the dump
        if (pid > 0) {
            final ProcessRecord pr;
            synchronized (mAm.mPidsSelfLocked) {
                pr = mAm.mPidsSelfLocked.get(pid);
            }
            if (pr != null) {
                // Don't attempt crash reporting for persistent apps
                if (pr.persistent) {
                    if (DEBUG) {
                        Slog.v(TAG, "Skipping report for persistent app " + pr);
                    }
                    return;
                }
                int bytes;
                do {
                    // get some data
                    bytes = Libcore.os.read(fd, buf, 0, buf.length);
                    if (bytes > 0) {
                        if (MORE_DEBUG) {
                            String s = new String(buf, 0, bytes, "UTF-8");
                            Slog.v(TAG, "READ=" + bytes + "> " + s);
                        }
                        // did we just get the EOD null byte?
                        if (buf[bytes - 1] == 0) {
                            // exclude the EOD token
                            os.write(buf, 0, bytes - 1);
                            break;
                        }
                        // no EOD, so collect it and read more
                        os.write(buf, 0, bytes);
                    }
                } while (bytes > 0);
                // Okay, we've got the report.
                if (DEBUG)
                    Slog.v(TAG, "processing");
                // debuggerd proceed.
                synchronized (mAm) {
                    pr.crashing = true;
                    pr.forceCrashReport = true;
                }
                // Crash reporting is synchronous but we want to let debuggerd
                // go about it business right away, so we spin off the actual
                // reporting logic on a thread and let it take it's time.
                final String reportString = new String(os.toByteArray(), "UTF-8");
                (new NativeCrashReporter(pr, signal, reportString)).start();
            } else {
                Slog.w(TAG, "Couldn't find ProcessRecord for pid " + pid);
            }
        } else {
            Slog.e(TAG, "Bogus pid!");
        }
    } catch (Exception e) {
        Slog.e(TAG, "Exception dealing with report", e);
    // ugh, fail.
    }
}
Also used : StructTimeval(libcore.io.StructTimeval) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ErrnoException(libcore.io.ErrnoException)

Example 2 with StructTimeval

use of libcore.io.StructTimeval in project robovm by robovm.

the class OpenSSLSocketImpl method setSoWriteTimeout.

/**
     * Note write timeouts are not part of the javax.net.ssl.SSLSocket API
     */
public void setSoWriteTimeout(int writeTimeoutMilliseconds) throws SocketException {
    this.writeTimeoutMilliseconds = writeTimeoutMilliseconds;
    StructTimeval tv = StructTimeval.fromMillis(writeTimeoutMilliseconds);
    try {
        Libcore.os.setsockoptTimeval(getFileDescriptor$(), SOL_SOCKET, SO_SNDTIMEO, tv);
    } catch (ErrnoException errnoException) {
        throw errnoException.rethrowAsSocketException();
    }
}
Also used : ErrnoException(libcore.io.ErrnoException) StructTimeval(libcore.io.StructTimeval)

Aggregations

ErrnoException (libcore.io.ErrnoException)2 StructTimeval (libcore.io.StructTimeval)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1