Setting SO_TIMEOUT on client socket channel
chudak
meadandale at gmail.com
Fri Oct 28 15:00:14 EDT 2011
This is what we are doing. Our client wrapper wraps the socket factory
(either regular or SSL):
public ClientSocketFactoryWrapper(SocketFactory socketFactory, int
soTimeout) {
this.socketFactory = socketFactory;
this.soTimeout = soTimeout;
}
@Override
public Socket createSocket() throws IOException {
return setOptions(socketFactory.createSocket());
}
snip...
protected Socket setOptions(Socket socket) throws SocketException {
socket.setSoTimeout(soTimeout);
return socket;
}
This wrapped socket factory is then injected into our custom
OioClientSocketChannelFactory which then passes it to a custom
OioClientSocketChannel which allows us to intercept the call below that
manually creates a new socket and instead uses the socket factory:
OioClientSocketChannel(
ChannelFactory factory,
ChannelPipeline pipeline,
ChannelSink sink) {
super(null, factory, pipeline, sink, new Socket());
fireChannelOpen(this);
}
We are currently setting the SO_TIMEOUT to a minute:
private static final int SOCKET_SO_TIMEOUT_IN_MS = 60000;
public void setSocketFactory(SocketFactory factory) {
this.socketFactory = new ClientSocketFactoryWrapper(factory,
SOCKET_SO_TIMEOUT_IN_MS);
}
The only places that I've found you set the socket timeout in the OIO code
is in the OioDatagramChannel where you set it to 10ms:
socket.setSoTimeout(10);
And in the OioServerSocketChannel where you set it to 1 second:
socket.setSoTimeout(1000);
However, we are using netty in a client application so it is not opening a
server socket, it is opening a client socket (OioClientSocketChannel)
Trustin Lee wrote:
>
> OK. What value are you exactly setting as SO_TIMEOUT? By default, Netty
> sets SO_TIMEOUT to 1 second already.
>
--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Setting-SO-TIMEOUT-on-client-socket-channel-tp6938557p6941388.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list