use of com.sun.jna.LastErrorException in project buck by facebook.
the class ReferenceCountedFileDescriptor method doClose.
private void doClose() throws IOException {
try {
UnixDomainSocketLibrary.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 doShutdown.
private void doShutdown(int how) throws IOException {
try {
int socketFd = fd.acquire();
if (socketFd != -1) {
UnixDomainSocketLibrary.shutdown(socketFd, how);
}
} catch (LastErrorException e) {
throw new IOException(e);
} finally {
fd.release();
isConnected = false;
}
}
use of com.sun.jna.LastErrorException in project jna by java-native-access.
the class Kernel32Util method formatMessage.
/**
* Format a message from the value obtained from
* {@link Kernel32#GetLastError()} or {@link Native#getLastError()}.
*
* @param code The error code
* @return Formatted message.
*/
public static String formatMessage(int code) {
PointerByReference buffer = new PointerByReference();
int nLen = Kernel32.INSTANCE.FormatMessage(WinBase.FORMAT_MESSAGE_ALLOCATE_BUFFER | WinBase.FORMAT_MESSAGE_FROM_SYSTEM | WinBase.FORMAT_MESSAGE_IGNORE_INSERTS, null, code, // TODO: // MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT)
0, buffer, 0, null);
if (nLen == 0) {
throw new LastErrorException(Native.getLastError());
}
Pointer ptr = buffer.getValue();
try {
String s = ptr.getWideString(0);
return s.trim();
} finally {
freeLocalMemory(ptr);
}
}
use of com.sun.jna.LastErrorException in project nailgun by facebook.
the class NGUnixDomainServerSocket method bind.
public synchronized void bind(SocketAddress endpoint) throws IOException {
if (!(endpoint instanceof NGUnixDomainServerSocketAddress)) {
throw new IllegalArgumentException("endpoint must be an instance of NGUnixDomainServerSocketAddress");
}
if (isBound) {
throw new IllegalStateException("Socket is already bound");
}
if (isClosed) {
throw new IllegalStateException("Socket is already closed");
}
NGUnixDomainServerSocketAddress unEndpoint = (NGUnixDomainServerSocketAddress) endpoint;
NGUnixDomainSocketLibrary.SockaddrUn address = new NGUnixDomainSocketLibrary.SockaddrUn(unEndpoint.getPath());
try {
int socketFd = fd.get();
NGUnixDomainSocketLibrary.bind(socketFd, address, address.size());
NGUnixDomainSocketLibrary.listen(socketFd, backlog);
isBound = true;
} catch (LastErrorException e) {
throw new IOException(e);
}
}
use of com.sun.jna.LastErrorException in project nailgun by facebook.
the class NGUnixDomainServerSocket method close.
public synchronized void close() throws IOException {
if (isClosed) {
throw new IllegalStateException("Socket is already closed");
}
try {
// Ensure any pending call to accept() fails.
NGUnixDomainSocketLibrary.close(fd.getAndSet(-1));
isClosed = true;
} catch (LastErrorException e) {
throw new IOException(e);
}
}
Aggregations