regarding NIO SocketChannel and SelectorKey
Basics: I have a SocketChannel which is supposed to read and write.
Context: My query is regarding the SelectoinKey for this channel. I understand that While I am writing onto this channel I would set the Key to OP_WRITE and soon after the write function is completed I should reset the SelectionKey to OP_READ
Querry: amid the write operation, if there is some data coming from the remote entity onto the same channel then the SelectionKey being in OP_WRITE mode will I lose the incoming data?
thanks in advance
Amit
# 1
> While I am writing onto this channel I would set the
> Key to OP_WRITE and soon after the write function is
> completed I should reset the SelectionKey to OP_READ
No. When you have data to write and you can't write it (i.e. you get a return value of zero from the channel.write() call) you should set the key to OP_WRITE, and when this event fires in the Selector (key.isWritable()) retry the write. When it succeeds completely, you then set the key back to OP_READ.
> Query: amid the write operation, if there is
> some data coming from the remote entity onto the same
> channel then the SelectionKey being in OP_WRITE mode
> will I lose the incoming data?
No.
ejpa at 2007-7-12 9:30:49 >
