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);
}
}
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);
}
}
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()));
}
}
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);
}
}
Aggregations