On 6/24/10 1:28 PM, Alexander Christian wrote:
On Thu, 24 Jun 2010 12:27:30 +0200, Emmanuel Lecharny
<[email protected]>
wrote:
But where? I checked out the complete source (1hr ago) and had a look
into
You *have* to fix the value if you want it to be something that fits
your need. If not, the socket buffer size won't be set, as we check that
the config value has changed before setting it.
That's exactly my expectation, yes.
Maybe I post a better code sample.
Test #1
--code--
NioSocketAcceptor acceptor = new NioSocketAcceptor();
System.out.println("recv buffer size =
"+acceptor.getSessionConfig().getReceiveBufferSize());
// ... setup filter chain ...
// ... setup handlers ...
acceptor.bind(new InetSocketAddress(55555));
System.out.println("recv buffer size =
"+acceptor.getSessionConfig().getReceiveBufferSize());
--/code--
--output--
recv buffer size = -1
recv buffer size = -1
--/output--
--> It's not possible to read the buffer's size before or after the
bind(). I always get -1 ..
You are reading the SessionConfig buffer size. As it has not been set,
you get -1, which is expected. Now, as you don't have an existing
socket, you can't get the OS default value.
Once upon a time, we were creating temporary sockets to get those
default values, but this was a bad idea, as on some condition it was
blocking MINA (typically when used in a brower or when the opened ports
are controlled), so we removed the associated code.
Test #2
--code--
NioSocketAcceptor acceptor = new NioSocketAcceptor();
System.out.println("recv buffer size =
"+acceptor.getSessionConfig().getReceiveBufferSize());
acceptor.getSessionConfig().setReceiveBufferSize(1);
System.out.println("changed recv buffer size =
"+acceptor.getSessionConfig().getReceiveBufferSize());
// ... setup filter chain ...
// ... setup handlers ...
acceptor.bind(new InetSocketAddress(55555));
System.out.println("recv buffer size =
"+acceptor.getSessionConfig().getReceiveBufferSize());
--/code--
--output--
recv buffer size = -1
changed recv buffer size = 1
recv buffer size = 1
--/output--
--> Output is still nto correct. I always get -1 before I set an value. I
set the buffer size to 1, so that the data transfer from client to server
should be horrible slow. But it isn't. So the change I made on buffer size
is not passed to the socket, but only to the session config object.
I have done the very same test, and I guarantee you that the buffer size
is set to 1. Here is the modified code that demonstrates the set value :
in NioSocketSession class :
...
public void setReceiveBufferSize(int size) {
try {
ch.socket().setReceiveBufferSize(size);
int sizeAfter = ch.socket().getReceiveBufferSize();
System.out.println( "Receive Buffer size = " + sizeAfter );
} catch (SocketException e) {
throw new RuntimeIoException(e);
}
Receive Buffer size = 1
here is the call stack :
Thread [NioSocketAcceptor-1] (Suspended)
NioSocketSession$SessionConfigImpl.setReceiveBufferSize(int) line: 304
NioSocketSession$SessionConfigImpl(AbstractSocketSessionConfig).doSetAll(IoSessionConfig)
line: 53
NioSocketSession$SessionConfigImpl(AbstractIoSessionConfig).setAll(IoSessionConfig)
line: 63
NioSocketSession.<init>(IoService, IoProcessor<NioSession>,
SocketChannel) line: 82
NioSocketAcceptor.accept(IoProcessor<NioSession>,
ServerSocketChannel) line: 223
NioSocketAcceptor.accept(IoProcessor, Object) line: 1
AbstractPollingIoAcceptor$Acceptor.processHandles(Iterator<H>)
line: 479
AbstractPollingIoAcceptor$Acceptor.run() line: 410
NamePreservingRunnable.run() line: 64
ThreadPoolExecutor$Worker.runTask(Runnable) line: 886
ThreadPoolExecutor$Worker.run() line: 908
Thread.run() line: 637
and my (modified) main class (I'm using the EchoServer example) :
public static void main(String[] args) throws Exception {
SocketAcceptor acceptor = new NioSocketAcceptor();
acceptor.setReuseAddress( true );
acceptor.getSessionConfig().setReceiveBufferSize( 1 );
<-------------
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
--
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com