import java.net.SocketAddress;
import java.net.StandardProtocolFamily;
import java.net.UnixDomainSocketAddress;
+import java.nio.channels.ClosedChannelException;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
public class IOUtils {
- private final static Logger logger = LoggerFactory.getLogger(IOUtils.class);
+ private static final Logger logger = LoggerFactory.getLogger(IOUtils.class);
private IOUtils() {
}
return () -> {
try {
return bufferedReader.readLine();
+ } catch (ClosedChannelException ignored) {
+ logger.trace("Line supplier has been interrupted.");
+ return null;
} catch (IOException e) {
logger.error("Error occurred while reading line", e);
return null;
return socketAddress;
}
- public static UnixDomainPrincipal getUnixDomainPrincipal(final SocketChannel channel) throws IOException {
+ public static String getUnixDomainPrincipal(final SocketChannel channel) throws IOException {
UnixDomainPrincipal principal = null;
try {
principal = channel.getOption(ExtendedSocketOptions.SO_PEERCRED);
} catch (UnsupportedOperationException | NoClassDefFoundError ignored) {
}
- return principal;
+ return principal == null ? null : principal.toString();
}
public static ServerSocketChannel bindSocket(final SocketAddress address) throws IOErrorException {
? ServerSocketChannel.open(StandardProtocolFamily.UNIX)
: ServerSocketChannel.open();
serverChannel.bind(address);
- logger.info("Listening on socket: " + address);
+ logger.debug("Listening on socket: " + address);
postBind(address);
} catch (IOException e) {
throw new IOErrorException("Failed to bind socket " + address + ": " + e.getMessage(), e);