本文整理汇总了Java中com.sun.jna.LastErrorException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java LastErrorException.getMessage方法的具体用法?Java LastErrorException.getMessage怎么用?Java LastErrorException.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jna.LastErrorException
的用法示例。
在下文中一共展示了LastErrorException.getMessage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPlatformSocketOption
import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
@Override
protected int setPlatformSocketOption(int sockfd, int level, int optName, TCPSocketOptions opt,
Integer optVal, int optSize) throws NativeErrorException {
try {
switch (optName) {
case OPT_TCP_KEEPALIVE_THRESHOLD:
// value required is in millis
final IntByReference timeout = new IntByReference(optVal.intValue() * 1000);
int result = setsockopt(sockfd, level, optName, timeout, optSize);
if (result == 0) {
// setting ABORT_THRESHOLD to be same as KEEPALIVE_THRESHOLD
return setsockopt(sockfd, level, OPT_TCP_KEEPALIVE_ABORT_THRESHOLD, timeout, optSize);
} else {
return result;
}
default:
throw new UnsupportedOperationException("unsupported option " + opt);
}
} catch (LastErrorException le) {
throw new NativeErrorException(le.getMessage(), le.getErrorCode(), le.getCause());
}
}
示例2: setEnvironment
import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
/**
* @see NativeCalls#setEnvironment(String, String)
*/
@Override
public synchronized void setEnvironment(final String name, final String value) {
if (name == null) {
throw new UnsupportedOperationException("setEnvironment() for name=NULL");
}
int res = -1;
Throwable cause = null;
try {
if (value != null) {
res = setenv(name, value, 1);
} else {
res = unsetenv(name);
}
} catch (LastErrorException le) {
cause = new NativeErrorException(le.getMessage(), le.getErrorCode(), le.getCause());
}
if (res != 0) {
throw new IllegalArgumentException(
"setEnvironment: given name=" + name + " (value=" + value + ')', cause);
}
// also change in java cached map
if (javaEnv != null) {
if (value != null) {
javaEnv.put(name, value);
} else {
javaEnv.remove(name);
}
}
}
示例3: daemonize
import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void daemonize(RehashServerOnSIGHUP callback) throws UnsupportedOperationException {
UnsupportedOperationException err = null;
try {
setsid();
} catch (LastErrorException le) {
// errno=EPERM indicates already group leader
if (le.getErrorCode() != EPERM) {
err = new UnsupportedOperationException("Failed in setsid() in daemonize() due to "
+ le.getMessage() + " (errno=" + le.getErrorCode() + ')');
}
}
// set umask to something consistent for servers
final int newMask = 022;
int oldMask = umask(newMask);
// check if old umask was more restrictive, and if so then set it back
if ((oldMask & 077) > newMask) {
umask(oldMask);
}
// catch the SIGHUP signal and invoke any callback provided
this.rehashCallback = callback;
this.hupHandler = new SignalHandler() {
@Override
public void callback(int signum) {
// invoke the rehash function if provided
final RehashServerOnSIGHUP rehashCb = rehashCallback;
if (signum == Signal.SIGHUP.getNumber() && rehashCb != null) {
rehashCb.rehash();
}
}
};
signal(Signal.SIGHUP.getNumber(), this.hupHandler);
// ignore SIGCHLD and SIGINT
signal(Signal.SIGCHLD.getNumber(), this.hupHandler);
signal(Signal.SIGINT.getNumber(), this.hupHandler);
if (err != null) {
throw err;
}
}
示例4: setEnvironment
import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
/**
* @see NativeCalls#setEnvironment(String, String)
*/
@Override
public synchronized void setEnvironment(final String name,
final String value) {
if (name == null) {
throw new UnsupportedOperationException(
"setEnvironment() for name=NULL");
}
int res = -1;
Throwable cause = null;
try {
if (value != null) {
res = setenv(name, value, 1);
}
else {
res = unsetenv(name);
}
} catch (LastErrorException le) {
cause = new NativeErrorException(le.getMessage(), le.getErrorCode(),
le.getCause());
}
if (res != 0) {
throw new IllegalArgumentException("setEnvironment: given name=" + name
+ " (value=" + value + ')', cause);
}
// also change in java cached map
if (javaEnv != null) {
if (value != null) {
javaEnv.put(name, value);
}
else {
javaEnv.remove(name);
}
}
}
示例5: setPlatformSocketOption
import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
@Override
protected int setPlatformSocketOption(int sockfd, int level, int optName,
TCPSocketOptions opt, Integer optVal, int optSize)
throws NativeErrorException {
try {
return setsockopt(sockfd, level, optName,
new IntByReference(optVal.intValue()), optSize);
} catch (LastErrorException le) {
throw new NativeErrorException(le.getMessage(), le.getErrorCode(),
le.getCause());
}
}
示例6: formatError
import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
private static String formatError(LastErrorException lee) {
try {
return strerror(lee.getErrorCode());
} catch (Throwable t) {
return lee.getMessage();
}
}
示例7: daemonize
import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void daemonize(RehashServerOnSIGHUP callback)
throws UnsupportedOperationException {
UnsupportedOperationException err = null;
try {
setsid();
} catch (LastErrorException le) {
// errno=EPERM indicates already group leader
if (le.getErrorCode() != EPERM) {
err = new UnsupportedOperationException(
"Failed in setsid() in daemonize() due to " + le.getMessage()
+ " (errno=" + le.getErrorCode() + ')');
}
}
// set umask to something consistent for servers
final int newMask = 022;
int oldMask = umask(newMask);
// check if old umask was more restrictive, and if so then set it back
if ((oldMask & 077) > newMask) {
umask(oldMask);
}
// catch the SIGHUP signal and invoke any callback provided
this.rehashCallback = callback;
this.hupHandler = new SignalHandler() {
@Override
public void callback(int signum) {
// invoke the rehash function if provided
final RehashServerOnSIGHUP rehashCb = rehashCallback;
if (signum == SIGHUP && rehashCb != null) {
rehashCb.rehash();
}
}
};
signal(SIGHUP, this.hupHandler);
// ignore SIGCHLD and SIGINT
signal(SIGCHLD, this.hupHandler);
signal(SIGINT, this.hupHandler);
// ignore tty signals
signal(SIGTSTP, this.hupHandler);
signal(SIGTTOU, this.hupHandler);
signal(SIGTTIN, this.hupHandler);
if (err != null) {
throw err;
}
}
示例8: setSocketOptions
import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Map<TCPSocketOptions, Throwable> setSocketOptions(Socket sock,
InputStream sockStream, Map<TCPSocketOptions, Object> optValueMap)
throws UnsupportedOperationException {
final TcpKeepAlive optValue = new TcpKeepAlive();
final int optSize = (Integer.SIZE / Byte.SIZE) * 3;
TCPSocketOptions errorOpt = null;
Throwable error = null;
for (Map.Entry<TCPSocketOptions, Object> e : optValueMap.entrySet()) {
TCPSocketOptions opt = e.getKey();
Object value = e.getValue();
// all options currently require an integer argument
if (value == null || !(value instanceof Integer)) {
throw new IllegalArgumentException("bad argument type "
+ (value != null ? value.getClass().getName() : "NULL") + " for "
+ opt);
}
switch (opt) {
case OPT_KEEPIDLE:
optValue.enabled = 1;
// in millis
optValue.keepalivetime = ((Integer)value).intValue() * 1000;
break;
case OPT_KEEPINTVL:
optValue.enabled = 1;
// in millis
optValue.keepaliveinterval = ((Integer)value).intValue() * 1000;
break;
case OPT_KEEPCNT:
errorOpt = opt;
error = new UnsupportedOperationException(
getUnsupportedSocketOptionMessage(opt));
break;
default:
throw new UnsupportedOperationException("unknown option " + opt);
}
}
final int sockfd = getSocketKernelDescriptor(sock, sockStream);
final IntByReference nBytes = new IntByReference(0);
try {
if (WSAIoctl(new NativeLong(sockfd), SIO_KEEPALIVE_VALS, optValue,
optSize, null, 0, nBytes, null, null) != 0) {
errorOpt = TCPSocketOptions.OPT_KEEPIDLE; // using some option here
error = new SocketException(getOSType() + ": error setting options: "
+ optValueMap);
}
} catch (LastErrorException le) {
// check if the error indicates that option is not supported
errorOpt = TCPSocketOptions.OPT_KEEPIDLE; // using some option here
if (le.getErrorCode() == WSAENOPROTOOPT) {
error = new UnsupportedOperationException(
getUnsupportedSocketOptionMessage(errorOpt),
new NativeErrorException(le.getMessage(), le.getErrorCode(),
le.getCause()));
}
else {
final SocketException se = new SocketException(getOSType()
+ ": failed to set options: " + optValueMap);
se.initCause(le);
error = se;
}
}
return errorOpt != null ? Collections.singletonMap(errorOpt, error)
: null;
}