Package jnr.ffi.byref

Examples of jnr.ffi.byref.IntByReference


    }

    public long posix_spawnp(String path, Collection<? extends SpawnFileAction> fileActions,
            CharSequence[] argv, CharSequence[] envp) {
        AbstractNumberReference<? extends Number> pid = Library.getRuntime(libc()).findType(TypeAlias.pid_t).size() == 4
                ? new IntByReference(-1) : new LongLongByReference(-1);
        Pointer nativeFileActions = nativeFileActions(fileActions);

        try {
            if (((UnixLibC) libc()).posix_spawnp(pid, path, nativeFileActions, null, argv, envp) < 0) {
                Errno e = Errno.valueOf(errno());
View Full Code Here


   
    private int childResult(WindowsChildRecord child, boolean overlay) {
        if (child == null) return -1;

        if (overlay) {
            IntByReference exitCode = new IntByReference();

            WindowsLibC libc = (WindowsLibC) libc();
            HANDLE handle = child.getProcess();
           
            libc.WaitForSingleObject(handle, WindowsLibC.INFINITE);
            libc.GetExitCodeProcess(handle, exitCode);
            libc.CloseHandle(handle);
            System.exit(exitCode.getValue());
        }

        return child.getPid();
    }
View Full Code Here

    }

    public UnixSocketChannel accept() throws IOException {
        UnixSocketAddress remote = new UnixSocketAddress();
        SockAddrUnix addr = remote.getStruct();
        IntByReference len = new IntByReference(addr.getMaximumLength());

        int clientfd = Native.accept(getFD(), addr, len);

        if (clientfd < 0) {
            throw new IOException("accept failed: " + Native.getLastErrorString());
View Full Code Here

    }

    public final boolean getKeepAlive() {
        ByteBuffer buf = ByteBuffer.allocate(4);
        buf.order(ByteOrder.BIG_ENDIAN);
        IntByReference ref = new IntByReference(4);

        Native.libsocket().getsockopt(channel.getFD(), SocketLevel.SOL_SOCKET.intValue(), SocketOption.SO_KEEPALIVE.intValue(), buf, ref);

        return buf.getInt(0) != 0;
    }
View Full Code Here

        return localAddress != null ? localAddress : (localAddress = getsockname(getFD()));
    }

    static UnixSocketAddress getpeername(int sockfd) {
        UnixSocketAddress remote = new UnixSocketAddress();
        IntByReference len = new IntByReference(remote.getStruct().getMaximumLength());

        if (Native.libc().getpeername(sockfd, remote.getStruct(), len) < 0) {
            throw new Error(Native.getLastErrorString());
        }
View Full Code Here

        return remote;
    }

    static UnixSocketAddress getsockname(int sockfd) {
        UnixSocketAddress remote = new UnixSocketAddress();
        IntByReference len = new IntByReference(remote.getStruct().getMaximumLength());

        if (Native.libc().getsockname(sockfd, remote.getStruct(), len) < 0) {
            throw new Error(Native.getLastErrorString());
        }
View Full Code Here

   
    private int childResult(WindowsChildRecord child, boolean overlay) {
        if (child == null) return -1;

        if (overlay) {
            IntByReference exitCode = new IntByReference();

            WindowsLibC libc = (WindowsLibC) libc();
            int handle = child.getProcess().intValue();
           
            libc.WaitForSingleObject(handle, WindowsLibC.INFINITE);
            libc.GetExitCodeProcess(handle, exitCode);
            libc.CloseHandle(handle);
            System.exit(exitCode.getValue());
        }

        return child.getPid();
    }
View Full Code Here

        return posix_spawnp(path, fileActions, nativeArgv, nativeEnv);
    }

    public int posix_spawnp(String path, List<? extends SpawnFileAction> fileActions,
            CharSequence[] argv, CharSequence[] envp) {
        IntByReference pid = new IntByReference(-1);
        Pointer nativeFileActions = nativeFileActions(fileActions);

        try {
            if (libc().posix_spawnp(pid, path, nativeFileActions, null, argv, envp) < 0) {
                Errno e = Errno.valueOf(errno());
                handler.error(e, e.description());
            }
        } finally {
            libc.posix_spawn_file_actions_destroy(nativeFileActions);
        }

        return pid.getValue();
    }
View Full Code Here

        int pid = RubyNumeric.num2int(args[i]);
        if (signal == 0) {
          jnr.ffi.Pointer ptr = kernel32().OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid);
          if(ptr != null && ptr.address() != -1) {
             try {
                           IntByReference status = new IntByReference(0);
                 if(kernel32().GetExitCodeProcess(ptr, status) == 0) {
                    throw runtime.newErrnoEPERMError("unable to call GetExitCodeProcess " + pid);
                 } else {
                     if(status.intValue() != STILL_ACTIVE) {
                     throw runtime.newErrnoEPERMError("Process exists but is not alive anymore " + pid);
                               }
                 }
             } finally {
               kernel32().CloseHandle(ptr);
             }
            
          } else {
              if (kernel32().GetLastError() == ERROR_INVALID_PARAMETER) {
                  throw runtime.newErrnoESRCHError();
              } else {
                  throw runtime.newErrnoEPERMError("Process does not exist " + pid);
              }
          }
          } else if (signal == 9) { //SIGKILL
            jnr.ffi.Pointer ptr = kernel32().OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, 0, pid);
                    if(ptr != null && ptr.address() != -1) {
              try {
                            IntByReference status = new IntByReference(0);
                  if(kernel32().GetExitCodeProcess(ptr, status) == 0) {
                      throw runtime.newErrnoEPERMError("unable to call GetExitCodeProcess " + pid); // todo better error messages
                  } else {
                      if (status.intValue() == STILL_ACTIVE) {
                        if (kernel32().TerminateProcess(ptr, 0) == 0) {
                           throw runtime.newErrnoEPERMError("unable to call TerminateProcess " + pid);
                         }
                                     // success                  
                    }
View Full Code Here

   
    private int childResult(WindowsChildRecord child, boolean overlay) {
        if (child == null) return -1;

        if (overlay) {
            IntByReference exitCode = new IntByReference();

            WindowsLibC libc = (WindowsLibC) libc();
            HANDLE handle = child.getProcess();
           
            libc.WaitForSingleObject(handle, WindowsLibC.INFINITE);
            libc.GetExitCodeProcess(handle, exitCode);
            libc.CloseHandle(handle);
            System.exit(exitCode.getValue());
        }

        return child.getPid();
    }
View Full Code Here

TOP

Related Classes of jnr.ffi.byref.IntByReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.