Projects tigase _server server-core Issues #351
SocketIO#write() should use while{} to write data to channel (#351)
Closed
Rick Zhang opened 1 decade ago

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);}

Andrzej Wójcik (Tigase) commented 1 decade ago

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 from dataToSend qeueue will be written to channel. This is not obvious as tmp buffer is DirectBuffer created only for temporary use, while we move position in buffer in dataBuffer as we write data to socket, which is used to check if we have any data to send.

issue 1 of 1
Type
Bug
Priority
Normal
Assignee
RedmineID
2075
Spent time
3h
Issue Votes (0)
Watchers (0)
Reference
tigase/_server/server-core#351
Please wait...
Page is in error, reload to recover