Problem accepting connections in nio-based-server running on linux Gentoo

Hey Guys,

I've encountered a strange problem in my nio-server-thingy running on Linux Gentoo:

I am using the standard handling connections loop for nio with going over the keys and checking which OP it is and i saw the following

there are times i do not getisAcceptable for clients i see their SYN packets in tethereal of this machine.

This is a very busy machine receiving lots of SYN packets, could it be that i did not configure something correctly on this machine so it does not direct all SYN packets to my application?

This is the code i am using - as i mentioned before, i see the SYN but i do not get the isAcceptable even. This is the basic loop handling connections in nio, am i missing something?

publicvoid handleConnections()throws IOException

{

log.finest(null);

int numberOfReadyChannels = selector.select(getSelectorTimeoutMillis());

if (numberOfReadyChannels == 0)

{

log.finest("No ready channels");

return;

}

for (Iterator<SelectionKey> iter = selector.selectedKeys().iterator(); iter.hasNext();)

{

SelectionKey key = iter.next();

iter.remove();

if (key.isValid() && key.isAcceptable())

{

log.finest("isAcceptable");

handleAccept(key);

}

if (key.isValid() && key.isConnectable())

{

log.finest("isConnectable");

handleConnect(key);

}

if (key.isValid() && key.isReadable())

{

log.finest("isReadable");

handleRead(key);

}

if (key.isValid() && key.isWritable())

{

handleWrite(key);

}

}

}

[2553 byte] By [snayita] at [2007-11-27 10:03:33]
# 1

> if (numberOfReadyChannels == 0)

> {

>log.finest("No ready channels");

>return;

>}

Why would you return on this condition? It just means nothing happened in the selection interval. Just log it, if you really think it needs logging, which I don't, and keep going. The problem is probably here.

>if (key.isValid() && key.isAcceptable())

>if (key.isValid() && key.isConnectable())

Are you connecting to other servers in this program? If not, isConnectable() can never happen in a server.

>if (key.isValid() && key.isReadable())

>if (key.isValid() && key.isWritable())

Too many is Valid() tests. Do one, before you test anything else.

As a matter of principle I am a believer that isWritable() should be handled before isReadable(). Just like letting passengers get off the bus before getting on.

ejpa at 2007-7-13 0:38:31 > top of Java-index,Java Essentials,Java Programming...