use of android.system.StructTimeval in project android_frameworks_base by AOSPA.
the class LocalSocketImpl method getOption.
public Object getOption(int optID) throws IOException {
if (fd == null) {
throw new IOException("socket not created");
}
try {
Object toReturn;
switch(optID) {
case SocketOptions.SO_TIMEOUT:
StructTimeval timeval = Os.getsockoptTimeval(fd, OsConstants.SOL_SOCKET, OsConstants.SO_SNDTIMEO);
toReturn = (int) timeval.toMillis();
break;
case SocketOptions.SO_RCVBUF:
case SocketOptions.SO_SNDBUF:
case SocketOptions.SO_REUSEADDR:
int osOpt = javaSoToOsOpt(optID);
toReturn = Os.getsockoptInt(fd, OsConstants.SOL_SOCKET, osOpt);
break;
case SocketOptions.SO_LINGER:
StructLinger linger = Os.getsockoptLinger(fd, OsConstants.SOL_SOCKET, OsConstants.SO_LINGER);
if (!linger.isOn()) {
toReturn = -1;
} else {
toReturn = linger.l_linger;
}
break;
case SocketOptions.TCP_NODELAY:
toReturn = Os.getsockoptInt(fd, OsConstants.IPPROTO_TCP, OsConstants.TCP_NODELAY);
break;
default:
throw new IOException("Unknown option: " + optID);
}
return toReturn;
} catch (ErrnoException e) {
throw e.rethrowAsIOException();
}
}
use of android.system.StructTimeval in project android_frameworks_base by AOSPA.
the class LocalSocketImpl method setOption.
public void setOption(int optID, Object value) throws IOException {
if (fd == null) {
throw new IOException("socket not created");
}
/*
* Boolean.FALSE is used to disable some options, so it
* is important to distinguish between FALSE and unset.
* We define it here that -1 is unset, 0 is FALSE, and 1
* is TRUE.
*/
int boolValue = -1;
int intValue = 0;
if (value instanceof Integer) {
intValue = (Integer) value;
} else if (value instanceof Boolean) {
boolValue = ((Boolean) value) ? 1 : 0;
} else {
throw new IOException("bad value: " + value);
}
try {
switch(optID) {
case SocketOptions.SO_LINGER:
StructLinger linger = new StructLinger(boolValue, intValue);
Os.setsockoptLinger(fd, OsConstants.SOL_SOCKET, OsConstants.SO_LINGER, linger);
break;
case SocketOptions.SO_TIMEOUT:
// The option must set both send and receive timeouts.
// Note: The incoming timeout value is in milliseconds.
StructTimeval timeval = StructTimeval.fromMillis(intValue);
Os.setsockoptTimeval(fd, OsConstants.SOL_SOCKET, OsConstants.SO_RCVTIMEO, timeval);
Os.setsockoptTimeval(fd, OsConstants.SOL_SOCKET, OsConstants.SO_SNDTIMEO, timeval);
break;
case SocketOptions.SO_RCVBUF:
case SocketOptions.SO_SNDBUF:
case SocketOptions.SO_REUSEADDR:
int osOpt = javaSoToOsOpt(optID);
Os.setsockoptInt(fd, OsConstants.SOL_SOCKET, osOpt, intValue);
break;
case SocketOptions.TCP_NODELAY:
Os.setsockoptInt(fd, OsConstants.IPPROTO_TCP, OsConstants.TCP_NODELAY, intValue);
break;
default:
throw new IOException("Unknown option: " + optID);
}
} catch (ErrnoException e) {
throw e.rethrowAsIOException();
}
}
use of android.system.StructTimeval in project android_frameworks_base by AOSPA.
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);
Os.setsockoptTimeval(fd, SOL_SOCKET, SO_RCVTIMEO, timeout);
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 = 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.
}
}
use of android.system.StructTimeval in project android_frameworks_base by crdroidandroid.
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);
Os.setsockoptTimeval(fd, SOL_SOCKET, SO_RCVTIMEO, timeout);
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 = 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.
}
}
use of android.system.StructTimeval in project android_frameworks_base by crdroidandroid.
the class LocalSocketImpl method getOption.
public Object getOption(int optID) throws IOException {
if (fd == null) {
throw new IOException("socket not created");
}
try {
Object toReturn;
switch(optID) {
case SocketOptions.SO_TIMEOUT:
StructTimeval timeval = Os.getsockoptTimeval(fd, OsConstants.SOL_SOCKET, OsConstants.SO_SNDTIMEO);
toReturn = (int) timeval.toMillis();
break;
case SocketOptions.SO_RCVBUF:
case SocketOptions.SO_SNDBUF:
case SocketOptions.SO_REUSEADDR:
int osOpt = javaSoToOsOpt(optID);
toReturn = Os.getsockoptInt(fd, OsConstants.SOL_SOCKET, osOpt);
break;
case SocketOptions.SO_LINGER:
StructLinger linger = Os.getsockoptLinger(fd, OsConstants.SOL_SOCKET, OsConstants.SO_LINGER);
if (!linger.isOn()) {
toReturn = -1;
} else {
toReturn = linger.l_linger;
}
break;
case SocketOptions.TCP_NODELAY:
toReturn = Os.getsockoptInt(fd, OsConstants.IPPROTO_TCP, OsConstants.TCP_NODELAY);
break;
default:
throw new IOException("Unknown option: " + optID);
}
return toReturn;
} catch (ErrnoException e) {
throw e.rethrowAsIOException();
}
}
Aggregations