mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
28.54.2014 f7fcf50a0de0704884c6f1c30db2c975b6af7b9d
opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/GrizzlyUtils.java
@@ -25,9 +25,8 @@
 */
package org.forgerock.opendj.grizzly;
import java.io.IOException;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.net.Socket;
import java.net.SocketException;
import java.nio.channels.SocketChannel;
import org.forgerock.i18n.slf4j.LocalizedLogger;
@@ -196,19 +195,33 @@
        // Configure socket options.
        final SocketChannel channel = (SocketChannel) ((TCPNIOConnection) connection).getChannel();
        setSocketOption(channel, StandardSocketOptions.TCP_NODELAY, tcpNoDelay, logger);
        setSocketOption(channel, StandardSocketOptions.SO_KEEPALIVE, keepAlive, logger);
        setSocketOption(channel, StandardSocketOptions.SO_REUSEADDR, reuseAddress, logger);
        setSocketOption(channel, StandardSocketOptions.SO_LINGER, linger, logger);
    }
    private static <T> void setSocketOption(final SocketChannel channel,
            final SocketOption<T> option, final T value, final LocalizedLogger logger) {
        final Socket socket = channel.socket();
        try {
            channel.setOption(option, value);
        } catch (final IOException e) {
            logger.traceException(e, "Unable to set " + option.name()
                    + " to %d on client connection", value);
            socket.setTcpNoDelay(tcpNoDelay);
        } catch (final SocketException e) {
            logger.traceException(e, "Unable to set TCP_NODELAY to %d on client connection",
                    tcpNoDelay);
        }
        try {
            socket.setKeepAlive(keepAlive);
        } catch (final SocketException e) {
            logger.traceException(e, "Unable to set SO_KEEPALIVE to %d on client connection",
                    keepAlive);
        }
        try {
            socket.setReuseAddress(reuseAddress);
        } catch (final SocketException e) {
            logger.traceException(e, "Unable to set SO_REUSEADDR to %d on client connection",
                    reuseAddress);
        }
        try {
            if (linger < 0) {
                socket.setSoLinger(false, 0);
            } else {
                socket.setSoLinger(true, linger);
            }
        } catch (final SocketException e) {
            logger.traceException(e, "Unable to set SO_LINGER to %d on client connection", linger);
        }
    }