The CompletionHandler<V,A> Interface in Asynchronous context

向雅 fyaoxy at
Thu Nov 12 03:50:08 PST 2009

2009/11/12 Alan Bateman <Alan.Bateman at>:
> 向雅 wrote:
>> Hi,
>> The CompletionHandler interface have notification method:
>>        public void completed(Integer result, T attachment);
>> In common case, read and write operation coding seems OK.
>> In most code, if handle the read operation, you should or must handle
>> result==-1 case.
>> And even if result==-1, maybe you still need check the read buffer to
>> see if have some incoming data.
> If the completed method is called to notify you of EOF then you are
> guaranteed that no bytes have been read. In order words, the result is
> always the number of bytes read or -1 to indicate EOF.
> If I understand your proposal correctly then you are proposing that we don't
> report the number of bytes read - is that right?

I mainly mean I dont think it as a great way that all code write
result ==-1? check.
Everybody do the check, Everybody run the check, some waste:)
some like the // signs case in protocol url.
so the additional method out.

About the bytecount read not report, look-seems I ever got. And I run
again some test,  not found unreport case.
from the code, I found:
 my complete method have a comment:
		if (result == -1) {
			// ONLY happen the channel closed by remote server
but my version repository tell me, in the close() method, I do later
add the buffer data check.


More information about the nio-dev mailing list