> I was trying out the source code from
>
[quoted text clipped - 3 lines]
> connected to the server. It stays at 100% until all clients
> disconnect.
I haven't tested the code, but I'll guess the problem is due to the
fact that they register interest in OP_WRITE for every connection.
Remove that and see if the problem goes away.
Normally a connection is writeable until write() fails. It's only then
you should register OP_WRITE, and then only until the connection
becomes writeable again.
There was a thread about this here recently, "NIO busywaiting".
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Remon van Vliet - 01 Feb 2006 12:37 GMT
>> I was trying out the source code from
>>
[quoted text clipped - 15 lines]
>
> /gordon
It's either the issue mentioned above or you using selectNow instead of
select. There are only two points in time where you want to register for
OP_WRITE namely after a connect/accept (using it as a notification for when
writing is possible) and when a write initially failed so you can try again
once OP_WRITE is selected. At all other times writing should be valid.
Remon van Vliet
rajatag - 01 Feb 2006 16:46 GMT
Thanks for the replies. I'll test these out and get back on this
thread.
rajatag - 01 Feb 2006 16:52 GMT
Another issue that just came to my mind ... if a write fails and I then
register interest in OP_WRITE, it means that the message that was
supposed to be sent in the failed attempt should be buffered by me?
Gordon Beaton - 01 Feb 2006 17:53 GMT
> Another issue that just came to my mind ... if a write fails and I then
> register interest in OP_WRITE, it means that the message that was
> supposed to be sent in the failed attempt should be buffered by me?
If write fails, then it's completely up to you to deal with it,
including buffering the message in order to try again later if that's
what you want to do.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
rajatag - 01 Feb 2006 17:55 GMT
thanks gordon,
also i have tried removing the OP_WRITE and it works great. CPU usage
is no longer 100%
Thank you so much!