Hello.
Can anyone tell me when, on what conditions SocketChannel.read(buffer) returns 0 bytes read? I’m puzzled with this… I have a server with registered OP_READ. Sometimes read event occurs but I read 0 bytes… why? I can simply ignore this by processing buffer only when I read more then 0 bytes but then my program dosen’t handle that situation at all, so I think it’s better to know something before completly ignorig it.
JavaDoc isn’t much help, only says that could happen, not why.
Thanks.
The only obvious situation I can think of is when your Buffer has 0 bytes remaining. Otherwise it makes little sense to me, otherthough when you’re reading bytes from multiple threads, you could already have ‘consumed’ the bytes. In non-blocking mode combined with registering for OP_READ, in a single threaded environment, I couldn’t give you a sensible reason.
What do you mean when it has 0 bytes remaining? Network buffer from whom I’m reading from or my read_buffer? Hmm… does every SocetChannel.read() completly puts in buffer what is has to or it just continues to write in it if he already has something in it? When I receive the data, I read everything and nothing more, of course then he’ll have 0 bytes remaining after I read it. Should I do something else with it when I’m done reading or what? Thanks.
Maybe you have 0 bytes of room left in your input buffer yo uare passign in?
That woudl be my first guess.