当前位置: 首页>>代码示例>>Java>>正文


Java LastErrorException类代码示例

本文整理汇总了Java中com.sun.jna.LastErrorException的典型用法代码示例。如果您正苦于以下问题:Java LastErrorException类的具体用法?Java LastErrorException怎么用?Java LastErrorException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LastErrorException类属于com.sun.jna包,在下文中一共展示了LastErrorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:NativeCallsJNAImpl.java

示例2: isProcessActive

import com.sun.jna.LastErrorException; //导入依赖的package包/类
/**
 * @see NativeCalls#isProcessActive(int)
 */
@Override
public boolean isProcessActive(final int processId) {
  try {
    final Pointer procHandle =
        Kernel32.OpenProcess(Kernel32.PROCESS_QUERY_INFORMATION, false, processId);
    final long hval;
    if (procHandle == null
        || (hval = Pointer.nativeValue(procHandle)) == Kernel32.INVALID_HANDLE || hval == 0) {
      return false;
    } else {
      final IntByReference status = new IntByReference();
      final boolean result = Kernel32.GetExitCodeProcess(procHandle, status) && status != null
          && status.getValue() == Kernel32.STILL_ACTIVE;
      Kernel32.CloseHandle(procHandle);
      return result;
    }
  } catch (LastErrorException le) {
    // some problem in getting process status
    return false;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:25,代码来源:NativeCallsJNAImpl.java

示例3: killProcess

import com.sun.jna.LastErrorException; //导入依赖的package包/类
/**
 * @see NativeCalls#killProcess(int)
 */
@Override
public boolean killProcess(final int processId) {
  try {
    final Pointer procHandle =
        Kernel32.OpenProcess(Kernel32.PROCESS_TERMINATE, false, processId);
    final long hval;
    if (procHandle == null
        || (hval = Pointer.nativeValue(procHandle)) == Kernel32.INVALID_HANDLE || hval == 0) {
      return false;
    } else {
      final boolean result = Kernel32.TerminateProcess(procHandle, -1);
      Kernel32.CloseHandle(procHandle);
      return result;
    }
  } catch (LastErrorException le) {
    // some problem in killing the process
    return false;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:NativeCallsJNAImpl.java

示例4: isProcessActive

import com.sun.jna.LastErrorException; //导入依赖的package包/类
/**
 * @see NativeCalls#isProcessActive(int)
 */
@Override
public boolean isProcessActive(final int processId) {
  try {
    final Pointer procHandle = Kernel32.OpenProcess(
        Kernel32.PROCESS_QUERY_INFORMATION, false, processId);
    final long hval;
    if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) ==
        Kernel32.INVALID_HANDLE || hval == 0) {
      return false;
    }
    else {
      final IntByReference status = new IntByReference();
      final boolean result = Kernel32.GetExitCodeProcess(procHandle, status)
          && status != null && status.getValue() == Kernel32.STILL_ACTIVE;
      Kernel32.CloseHandle(procHandle);
      return result;
    }
  } catch (LastErrorException le) {
    // some problem in getting process status
    return false;
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:26,代码来源:NativeCallsJNAImpl.java

示例5: killProcess

import com.sun.jna.LastErrorException; //导入依赖的package包/类
/**
 * @see NativeCalls#killProcess(int)
 */
@Override
public boolean killProcess(final int processId) {
  try {
    final Pointer procHandle = Kernel32.OpenProcess(
        Kernel32.PROCESS_TERMINATE, false, processId);
    final long hval;
    if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) ==
        Kernel32.INVALID_HANDLE || hval == 0) {
      return false;
    }
    else {
      final boolean result = Kernel32.TerminateProcess(procHandle, -1);
      Kernel32.CloseHandle(procHandle);
      return result;
    }
  } catch (LastErrorException le) {
    // some problem in killing the process
    return false;
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:24,代码来源:NativeCallsJNAImpl.java

示例6: lockFile

import com.sun.jna.LastErrorException; //导入依赖的package包/类
public void lockFile(Path path) {
	String absolutefilepath = path.toAbsolutePath().toString();
	long fileSize = path.toFile().length();
	if (fileSize == 0) {
		return;
	}
	int fd = -1;
	try {
		fd = CLibrary.open(absolutefilepath, CLibrary.O_RDONLY, 0);
		Pointer addr = CLibrary.mmap(null, new SizeT(fileSize), CLibrary.PROT_READ, CLibrary.MAP_SHARED, fd, new CLibrary.OffT());
		CLibrary.mlock(addr, new SizeT(fileSize));
		lockedFiles.put(absolutefilepath, new LockedFileInfo(fd, addr, fileSize));
		ExceptionShutdown.log("Locked "+absolutefilepath);
	} catch (LastErrorException e) {
		if (fd != -1) {
			CLibrary.close(fd);
		}
		ExceptionShutdown.err("Failed to lock file "+absolutefilepath + ", err code: "+e.getErrorCode());
	}
}
 
开发者ID:Shevchik,项目名称:DirectoryCacher,代码行数:21,代码来源:FileLocker.java

示例7: read

import com.sun.jna.LastErrorException; //导入依赖的package包/类
@Override
public int read(byte[] b, int off, int len) throws IOException {
  if (b == null) {
    throw new NullPointerException();
  }
  if (off < 0 || len < 0 || len > b.length - off) {
    throw new IndexOutOfBoundsException();
  }
  if (len == 0) {
    return 0;
  }
  int n;
  try {
    n = cLib.recv(fd, b, len, 0);
  } catch (LastErrorException e) {
    throw new IOException("error: " + cLib.strerror(e.getErrorCode()));
  }
  if (n == 0) {
    return -1;
  }
  return n;
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:UnixSocketInputStream.java

示例8: read

import com.sun.jna.LastErrorException; //导入依赖的package包/类
@Override
public int read(byte[] bytesEntry, int off, int len) throws IOException {
    try {
        if (off > 0) {
            int bytes = 0;
            int remainingLength = len;
            int size;
            byte[] data = new byte[(len < 10240) ? len : 10240];
            do {
                size = recv(fd, data, (remainingLength < 10240) ? remainingLength : 10240, 0);
                if (size > 0) {
                    System.arraycopy(data, 0, bytesEntry, off, size);
                    bytes += size;
                    off += size;
                    remainingLength -= size;
                }
            } while ((remainingLength > 0) && (size > 0));
            return bytes;
        } else {
            return recv(fd, bytesEntry, len, 0);
        }
    } catch (LastErrorException lee) {
        throw new IOException("native read() failed : " + formatError(lee));
    }
}
 
开发者ID:MariaDB,项目名称:mariadb-connector-j,代码行数:26,代码来源:UnixDomainSocket.java

示例9: 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);
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:33,代码来源:NativeCallsJNAImpl.java

示例10: 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;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:43,代码来源:NativeCallsJNAImpl.java

示例11: fallocateFD

import com.sun.jna.LastErrorException; //导入依赖的package包/类
@Override
protected void fallocateFD(int fd, long offset, long len) throws LastErrorException {
  int errno = posix_fallocate64(fd, offset, len);
  if (errno != 0) {
    throw new LastErrorException(errno);
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:8,代码来源:NativeCallsJNAImpl.java

示例12: getTerminalAttrs

import com.sun.jna.LastErrorException; //导入依赖的package包/类
private static Termios getTerminalAttrs (int fd) throws IOException {
Termios termios = new Termios();
try {
   int rc = libc.tcgetattr(fd, termios);
   if (rc != 0) {
      throw new RuntimeException("tcgetattr() failed."); }}
 catch (LastErrorException e) {
   throw new IOException("tcgetattr() failed.", e); }
return termios; }
 
开发者ID:ofrank123,项目名称:TheIntellectualOctocats,代码行数:10,代码来源:RawConsoleInput.java

示例13: setTerminalAttrs

import com.sun.jna.LastErrorException; //导入依赖的package包/类
private static void setTerminalAttrs (int fd, Termios termios) throws IOException {
try {
   int rc = libc.tcsetattr(fd, LibcDefs.TCSANOW, termios);
   if (rc != 0) {
      throw new RuntimeException("tcsetattr() failed."); }}
 catch (LastErrorException e) {
   throw new IOException("tcsetattr() failed.", e); }}
 
开发者ID:ofrank123,项目名称:TheIntellectualOctocats,代码行数:8,代码来源:RawConsoleInput.java

示例14: detectAutoProxyConfigUrl

import com.sun.jna.LastErrorException; //导入依赖的package包/类
/**
 * Finds the URL for the Proxy Auto-Configuration (PAC) file using WPAD.
 * This is merely a wrapper around
 * {@link WinHttp#WinHttpDetectAutoProxyConfigUrl(com.sun.jna.platform.win32.WinDef.DWORD, com.github.markusbernhardt.proxy.jna.win.WTypes2.LPWSTRByReference)
 * WinHttpDetectAutoProxyConfigUrl}
 *
 * <p>
 * This method is blocking and may take some time to execute.
 * 
 * @param dwAutoDetectFlags
 * @return the url of the PAC file or {@code null} if it cannot be located
 *         using WPAD method.
 */
public static String detectAutoProxyConfigUrl(WinDef.DWORD dwAutoDetectFlags) {

    WTypes2.LPWSTRByReference ppwszAutoConfigUrl = new WTypes2.LPWSTRByReference();
    boolean result = false;
    try {
        result = WinHttp.INSTANCE.WinHttpDetectAutoProxyConfigUrl(dwAutoDetectFlags, ppwszAutoConfigUrl);
    } catch (LastErrorException ex) {
        if (ex.getErrorCode() == WinHttp.ERROR_WINHTTP_AUTODETECTION_FAILED) {
            // This error is to be expected. It just means that the lookup
            // using either DHCP, DNS or both, failed because there wasn't
            // a useful reply from DHCP / DNS. (meaning the site hasn't
            // configured their DHCP Server or their DNS Server for WPAD)
            return null;
        }
        // Something more serious is wrong. There isn't much we can do
        // about it but at least we would like to log it.
        Logger.log(WinHttpHelpers.class, Logger.LogLevel.ERROR,
                "Windows function WinHttpDetectAutoProxyConfigUrl returned error : {0}", ex.getMessage());
        return null;
    }
    if (result) {
        return ppwszAutoConfigUrl.getString();
    } else {
        return null;
    }
}
 
开发者ID:MarkusBernhardt,项目名称:proxy-vole,代码行数:40,代码来源:WinHttpHelpers.java

示例15: getWindowsFileInfo

import com.sun.jna.LastErrorException; //导入依赖的package包/类
/**
 * Gets {@link VS_FIXEDFILEINFO} from the Windows API for a specified
 * {@link Path}.
 * <p>
 * <b>Must only be called on Windows</b>
 *
 * @param path the {@link Path} the get file information for.
 * @param throwLastError whether or not to throw a
 *            {@link LastErrorException} if it occurs during the operation.
 * @return The generated {@link VS_FIXEDFILEINFO} instance or {@code null}
 * @throws IllegalStateException If called on a non-Windows platform.
 * @throws LastErrorException If {@code throwLastError} is {@code true} and
 *             {@code LastError} has a non-zero return value during the
 *             operation.
 */
@Nullable
public static VS_FIXEDFILEINFO getWindowsFileInfo(@Nonnull Path path, boolean throwLastError) {
	if (!Platform.isWindows()) {
		throw new IllegalStateException("getWindowsFileInfo() can only be called on Windows");
	}
	VS_FIXEDFILEINFO fixedFileInfo = null;
	IntByReference ignored = new IntByReference();
	try {
		int infoSize = WindowsVersion.INSTANCE.GetFileVersionInfoSizeW(path.toString(), ignored);
		if (infoSize > 0) {
			Memory data = new Memory(infoSize);
			if (WindowsVersion.INSTANCE.GetFileVersionInfoW(path.toString(), 0, infoSize, data)) {
				PointerByReference lplpBuffer = new PointerByReference();
				IntByReference puLen = new IntByReference();
				if (WindowsVersion.INSTANCE.VerQueryValueW(data, "\\", lplpBuffer, puLen) && puLen.getValue() > 0) {
					fixedFileInfo = new VS_FIXEDFILEINFO(lplpBuffer.getValue());
				}
			}
		}
	} catch (LastErrorException e) {
		if (throwLastError) {
			throw e;
		}
		LOGGER.debug("getWindowsFileInfo for \"{}\" failed with: {}", path, e.getMessage());
		LOGGER.trace("", e);
	}
	return fixedFileInfo;
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:44,代码来源:Version.java


注:本文中的com.sun.jna.LastErrorException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。