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


Java LastErrorException.getErrorCode方法代码示例

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


在下文中一共展示了LastErrorException.getErrorCode方法的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: 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

示例3: isProcessActive

import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
/**
 * @see NativeCalls#isProcessActive(int)
 */
@Override
public boolean isProcessActive(final int processId) {
  try {
    return kill(processId, 0) == 0;
  } catch (LastErrorException le) {
    if (le.getErrorCode() == EPERM) {
      // Process exists; it probably belongs to another user (bug 27698).
      return true;
    }
  }
  return false;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:16,代码来源:NativeCallsJNAImpl.java

示例4: 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

示例5: 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

示例6: 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:gemxd,项目名称:gemfirexd-oss,代码行数:38,代码来源:NativeCallsJNAImpl.java

示例7: 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());
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:13,代码来源:NativeCallsJNAImpl.java

示例8: getAffinity

import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
public long getAffinity() {
    final CLibrary lib = CLibrary.INSTANCE;
    // TODO where are systems with 64+ cores...
    final long cpuset[] = new long[16];
    try {
        final int ret = lib.sched_getaffinity(0, 16 * (Long.SIZE / 8), cpuset);
        if (ret < 0)
            throw new IllegalStateException("sched_getaffinity((" + Long.SIZE / 8 + ") , &(" + cpuset + ") ) return " + ret);
        return cpuset[0];
    } catch (LastErrorException e) {
        throw new IllegalStateException("sched_getaffinity((" + Long.SIZE / 8 + ") , &(" + cpuset + ") ) errorNo=" + e.getErrorCode(), e);
    }
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:14,代码来源:PosixJNAAffinity.java

示例9: setAffinity

import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
public void setAffinity(final long affinity) {
    final CLibrary lib = CLibrary.INSTANCE;
    try {
        //fixme: where are systems with more then 64 cores...
        long affinityMask[] = new long[16];
        affinityMask[0] = affinity;
        final int ret = lib.sched_setaffinity(0, 16 * (Long.SIZE / 8), affinityMask);
        if (ret < 0) {
            throw new IllegalStateException("sched_setaffinity((" + Long.SIZE / 8 + ") , &(" + affinity + ") ) return " + ret);
        }
    } catch (LastErrorException e) {
        throw new IllegalStateException("sched_getaffinity((" + Long.SIZE / 8 + ") , &(" + affinity + ") ) errorNo=" + e.getErrorCode(), e);
    }
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:15,代码来源:PosixJNAAffinity.java

示例10: dispose

import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
/**
 * Releases all resources associated with this class.
 * This method calls {@link #flushRequests} to cancel all pending requests.
 */
public void dispose() throws IOException {
    try {
        flushRequests();
    } catch (LastErrorException e) {
        // This happens when the device has been disconnected.
        if (e.getErrorCode() != ENODEV) {
            throw e;
        }
    }
}
 
开发者ID:ToxicBakery,项目名称:Isochronous,代码行数:15,代码来源:UsbIso.java

示例11: reapRequest

import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
/**
 * Returns a completed request.
 * <p>
 * A <code>Request</code> object returned by this method has been removed from the queue and can be re-used by calling {@link Request#initialize} and {@link Request#submit}.
 *
 * @param wait <code>true</code> to wait until a completed request is available. <code>false</code> to return immediately when no
 *             completed request is available.
 * @return A <code>Request</code> object representing a completed request, or <code>null</code> if
 * <code>wait</code> is <code>false</code> and no completed request is available at the time.
 */
public Request reapRequest(boolean wait) throws IOException {
    PointerByReference urbPointer = new PointerByReference();
    int func = wait ? USBDEVFS_REAPURB : USBDEVFS_REAPURBNDELAY;
    int rc;
    try {
        rc = libc.ioctl(fileDescriptor, func, urbPointer);
    } catch (LastErrorException e) {
        if (e.getErrorCode() == EAGAIN && !wait) {
            return null;
        }
        throw e;
    }
    if (rc != 0) {
        throw new IOException("ioctl(USBDEVFS_REAPURB*) failed, rc=" + rc + ".");
    }
    int urbNdx = Urb.getUserContext(urbPointer.getValue());
    if (urbNdx < 0 || urbNdx >= requests.size()) {
        throw new IOException("URB.userContext returned by ioctl(USBDEVFS_REAPURB*) is out of range.");
    }
    Request req = requests.get(urbNdx);
    if (req.urbAddr != Pointer.nativeValue(urbPointer.getValue())) {
        throw new IOException("Address of URB returned by ioctl(USBDEVFS_REAPURB*) does not match.");
    }
    if (!req.queued) {
        throw new IOException("URB returned by ioctl(USBDEVFS_REAPURB*) was not queued.");
    }
    req.queued = false;
    req.initialized = false;
    return req;
}
 
开发者ID:ToxicBakery,项目名称:Isochronous,代码行数:41,代码来源:UsbIso.java

示例12: cancel

import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
/**
 * Cancels a queued request.
 * The request remains within the queue amd must be removed from the queue by calling {@link UsbIso#reapRequest}.
 */
public void cancel() throws IOException {
    int rc;
    try {
        rc = libc.ioctl(fileDescriptor, USBDEVFS_DISCARDURB, urbAddr);
    } catch (LastErrorException e) {
        if (e.getErrorCode() == EINVAL) {                 // This happens if the request has already completed.
            return;
        }
        throw e;
    }
    if (rc != 0) {
        throw new IOException("ioctl(USBDEVFS_DISCARDURB) failed, rc=" + rc);
    }
}
 
开发者ID:ToxicBakery,项目名称:Isochronous,代码行数:19,代码来源:UsbIso.java

示例13: preBlow

import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
@Override
public void preBlow(String path, long maxSize, boolean preAllocate) throws IOException {
  final org.apache.geode.LogWriter logger;
  if (InternalDistributedSystem.getAnyInstance() != null) {
    logger = InternalDistributedSystem.getAnyInstance().getLogWriter();
  } else {
    logger = null;
  }

  if (logger != null && logger.fineEnabled()) {
    logger.fine("DEBUG preBlow called for path = " + path);
  }
  if (!preAllocate || !hasFallocate(path)) {
    super.preBlow(path, maxSize, preAllocate);
    if (logger != null && logger.fineEnabled()) {
      logger.fine("DEBUG preBlow super.preBlow 1 called for path = " + path);
    }
    return;
  }
  int fd = -1;
  boolean unknownError = false;
  try {
    fd = createFD(path, 00644);
    if (!isOnLocalFileSystem(path)) {
      super.preBlow(path, maxSize, preAllocate);
      if (logger != null && logger.fineEnabled()) {
        logger.fine("DEBUG preBlow super.preBlow 2 called as path = " + path
            + " not on local file system");
      }
      if (DiskStoreImpl.TEST_NO_FALLOC_DIRS != null) {
        DiskStoreImpl.TEST_NO_FALLOC_DIRS.add(path);
      }
      return;
    }
    fallocateFD(fd, 0L, maxSize);
    if (DiskStoreImpl.TEST_CHK_FALLOC_DIRS != null) {
      DiskStoreImpl.TEST_CHK_FALLOC_DIRS.add(path);
    }
    if (logger != null && logger.fineEnabled()) {
      logger.fine("DEBUG preBlow posix_fallocate called for path = " + path
          + " and ret = 0 maxsize = " + maxSize);
    }
  } catch (LastErrorException le) {
    if (logger != null && logger.fineEnabled()) {
      logger.fine("DEBUG preBlow posix_fallocate called for path = " + path + " and ret = "
          + le.getErrorCode() + " maxsize = " + maxSize);
    }
    // check for no space left on device
    if (le.getErrorCode() == ENOSPC) {
      unknownError = false;
      throw new IOException("Not enough space left on device");
    } else {
      unknownError = true;
    }
  } finally {
    if (fd >= 0) {
      try {
        close(fd);
      } catch (Exception e) {
        // ignore
      }
    }
    if (unknownError) {
      super.preBlow(path, maxSize, preAllocate);
      if (logger != null && logger.infoEnabled()) {
        logger.fine("DEBUG preBlow super.preBlow 3 called for path = " + path);
      }
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:71,代码来源:NativeCallsJNAImpl.java

示例14: 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;
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:49,代码来源:NativeCallsJNAImpl.java

示例15: preBlow

import com.sun.jna.LastErrorException; //导入方法依赖的package包/类
@Override
public void preBlow(String path, long maxSize, boolean preAllocate)
    throws IOException {
  final Logger logger = ClientSharedUtils.getLogger();
  if (logger != null && logger.isLoggable(Level.FINE)) {
    logger.fine("DEBUG preBlow called for path = " + path);
  }
  if (!preAllocate || !hasFallocate()) {
    super.preBlow(path, maxSize, preAllocate);
    if (logger != null && logger.isLoggable(Level.FINE)) {
      logger.fine("DEBUG preBlow super.preBlow 1 called for path = "
          + path);
    }
    return;
  }
  int fd = -1;
  boolean unknownError = false;
  try {
    fd = createFD(path, 00644);
    if (!isOnLocalFileSystem(path)) {
      super.preBlow(path, maxSize, preAllocate);
      if (logger != null && logger.isLoggable(Level.FINE)) {
        logger.fine("DEBUG preBlow super.preBlow 2 called as path = "
            + path + " not on local file system");
      }
      if (TEST_NO_FALLOC_DIRS != null) {
        TEST_NO_FALLOC_DIRS.add(path);
      }
      return;
    }
    fallocateFD(fd, 0L, maxSize);
    if (TEST_CHK_FALLOC_DIRS != null) {
      TEST_CHK_FALLOC_DIRS.add(path);
    }
    if (logger != null && logger.isLoggable(Level.FINE)) {
      logger.fine("DEBUG preBlow posix_fallocate called for path = " + path
          + " and ret = 0 maxsize = " + maxSize);
    }
  } catch (LastErrorException le) {
    if (logger != null && logger.isLoggable(Level.FINE)) {
      logger.fine("DEBUG preBlow posix_fallocate called for path = " + path
          + " and ret = " + le.getErrorCode() + " maxsize = " + maxSize);
    }
    // check for no space left on device
    if (le.getErrorCode() == ENOSPC) {
      unknownError = false;
      throw new IOException("Not enough space left on device");
    }
    else {
      unknownError = true;
    }
  } finally {
    if (fd >= 0) {
      try {
        close(fd);
      } catch (Exception e) {
        // ignore
      }
    }
    if (unknownError) {
      super.preBlow(path, maxSize, preAllocate);
      if (logger != null && logger.isLoggable(Level.FINE)) {
        logger.fine("DEBUG preBlow super.preBlow 3 called for path = "
            + path);
      }
    }
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:69,代码来源:NativeCallsJNAImpl.java


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