-
This is not an error. If you would look closer
res = channel.write(tmp)
is inside while loop which ends only when all data from all buffers fromdataToSend
qeueue will be written to channel. This is not obvious as tmp buffer isDirectBuffer
created only for temporary use, while we move position in buffer indataBuffer
as we write data to socket, which is used to check if we have any data to send.
Type |
Bug
|
Priority |
Normal
|
Assignee | |
RedmineID |
2075
|
Spent time |
0
|
Issue Votes (0)
Watchers (0)
I think it should be a bug when I reading source code of SocketIO.The code fragment is in write() method:
res = channel.write(tmp);
In java.nio.channels.WritableByteChannel#write(),it comments like this:
Unless otherwise specified, a write operation will return only after
writing all of the r requested bytes. Some types of channels,
depending upon their state, may write only some of the bytes or possibly
none at all. A socket channel in non-blocking mode, for example, cannot
write any more bytes than are free in the socket's output buffer.
It hasn't illustrate clearly whether all data can be wrote when SocketChannel is in unblocking status.So I think the more strict code should like this:
while(tmp.hasRemaining()){channel.write(tmp);}