Le 3/26/14 8:16 PM, Archer, Garry a écrit :
> Emmanuel, thank you so much for your kind response!
>
> I've been distracted by another project at the moment, so I will have to get 
> back to this...
>
> What I was looking at in the Mina code was what happens when the 
> 'WriteRequestQueue' is polled and there is a 'WriteRequest' at the head of 
> the queue which has a non-empty message (IoBuffer) to write to the session.  
> The write method throws an IOException and this causes the session to close.  
> The buffer is suppose to be non-empty (has length > 0), so I'm not sure why 
> the write method throws an IOException.  I haven't been able to debug that 
> far yet.  It may be some byte in the message causing the problem.
The way it works is a bit cryptic.

When your message has been encoded, it's pushed into a queue, period.
Then the stack is unfolded, and at the very end, if the write queue is
not empty, and if the selectionKey is ready for write, we will try to
write the message pulled from the queue (untl the socket is full). Now,
we have two use cases :
- the queue is empty : we are done, we switch back the selectionKey not
ready for Write (otherwise we will be awakened no matter what !)
- the queue is not empty : we have to wait for the socket to be ready,
which will be the case when the selectionKey will receive the OP_WRITE
event.

In both case, for *every* message being fully sent, we generate a
messageSent event (and we may emit more than one).

If you ask me how does the lower layer knows that a full message has
been sent, when all that it sees is a byte[], I'll answer that we use a
trick : in the encoder, we write a empty fake message in the queue to
inform it that this is the end of a message...

At this point, it's hrad to tell you where the exception is coming from,
but most certianly from your encoder.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 

Reply via email to