use of android.system.StructLinger in project android_frameworks_base by DirtyUnicorns.
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.StructLinger in project platform_frameworks_base by android.
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.StructLinger 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.StructLinger 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.StructLinger 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