Search in sources :

Example 6 with LastErrorException

use of com.sun.jna.LastErrorException in project nailgun by facebook.

the class ReferenceCountedFileDescriptor method doClose.

private void doClose() throws IOException {
    try {
        NGUnixDomainSocketLibrary.close(fd);
        fd = -1;
    } catch (LastErrorException e) {
        throw new IOException(e);
    }
}
Also used : LastErrorException(com.sun.jna.LastErrorException) IOException(java.io.IOException)

Example 7 with LastErrorException

use of com.sun.jna.LastErrorException in project buck by facebook.

the class UnixDomainSocket method createSocketWithPath.

/**
   * Creates a Unix domain socket bound to a path.
   */
public static UnixDomainSocket createSocketWithPath(Path path) throws IOException {
    int fd = -1;
    try {
        fd = UnixDomainSocketLibrary.socket(UnixDomainSocketLibrary.PF_LOCAL, UnixDomainSocketLibrary.SOCK_STREAM, 0);
        UnixDomainSocketLibrary.SockaddrUn address = new UnixDomainSocketLibrary.SockaddrUn(path.toString());
        UnixDomainSocketLibrary.connect(fd, address, address.size());
        return new UnixDomainSocket(new ReferenceCountedFileDescriptor(fd));
    } catch (LastErrorException e) {
        if (fd != -1) {
            UnixDomainSocketLibrary.close(fd);
        }
        throw new IOException(e);
    }
}
Also used : LastErrorException(com.sun.jna.LastErrorException) IOException(java.io.IOException)

Example 8 with LastErrorException

use of com.sun.jna.LastErrorException in project opennms by OpenNMS.

the class NativeDatagramSocket method allowFragmentation.

public void allowFragmentation(final int level, final int option_name, final boolean frag) throws IOException {
    final int socket = getSock();
    if (socket < 0) {
        throw new IOException("Invalid socket!");
    }
    final IntByReference dontfragment = new IntByReference(frag == true ? 0 : 1);
    try {
        setsockopt(socket, level, option_name, dontfragment.getPointer(), Pointer.SIZE);
    } catch (final LastErrorException e) {
        throw new IOException("setsockopt: " + strerror(e.getErrorCode()));
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) LastErrorException(com.sun.jna.LastErrorException) IOException(java.io.IOException)

Example 9 with LastErrorException

use of com.sun.jna.LastErrorException in project nailgun by facebook.

the class NGUnixDomainServerSocket method accept.

public Socket accept() throws IOException {
    // indefinitely, causing another thread's call to close() to deadlock.
    synchronized (this) {
        if (!isBound) {
            throw new IllegalStateException("Socket is not bound");
        }
        if (isClosed) {
            throw new IllegalStateException("Socket is already closed");
        }
    }
    try {
        NGUnixDomainSocketLibrary.SockaddrUn sockaddrUn = new NGUnixDomainSocketLibrary.SockaddrUn();
        IntByReference addressLen = new IntByReference();
        addressLen.setValue(sockaddrUn.size());
        int clientFd = NGUnixDomainSocketLibrary.accept(fd.get(), sockaddrUn, addressLen);
        return new NGUnixDomainSocket(clientFd);
    } catch (LastErrorException e) {
        throw new IOException(e);
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) LastErrorException(com.sun.jna.LastErrorException) IOException(java.io.IOException)

Aggregations

LastErrorException (com.sun.jna.LastErrorException)9 IOException (java.io.IOException)8 IntByReference (com.sun.jna.ptr.IntByReference)2 Pointer (com.sun.jna.Pointer)1 PointerByReference (com.sun.jna.ptr.PointerByReference)1