My dear friends,

I got a question when I read the source code,how is the SocketIoProcessor
class dealing the situation that the buf is smaller than the data expected
in the SocketChannel?

sorry for my poor English.

Source code in the SocketIoProcessor class  

    private void read(SocketSessionImpl session) {

        ByteBuffer buf = ByteBuffer.allocate(session.getReadBufferSize());

        SocketChannel ch = session.getChannel();

 

        try {

            int readBytes = 0;

            int ret;

 

            try {

                while ((ret = ch.read(buf.buf())) > 0) {

                    readBytes += ret;

                }

            } finally {

                buf.flip();

            }

 

            session.increaseReadBytes(readBytes);

 

            if (readBytes > 0) {

                session.getFilterChain().fireMessageReceived(session, buf);

                buf = null;

 

                if (readBytes * 2 < session.getReadBufferSize()) {

                    session.decreaseReadBufferSize();

                } else if (readBytes == session.getReadBufferSize()) {

                    session.increaseReadBufferSize();

                }

            }

            if (ret < 0) {

                scheduleRemove(session);

            }

        } catch (Throwable e) {

            if (e instanceof IOException)

                scheduleRemove(session);

            session.getFilterChain().fireExceptionCaught(session, e);

        } finally {

            if (buf != null)

                buf.release();

        }

    }

 

Best  regards,
Andy (张园)
Mobile Internet Division
-------------------------------------------------------
Address: Building A9,Neusoft Park,No.2 Xinxiu Street,Hunnan 
         Industrial Park ,Shenyang 110179, PRC
    Tel: +86 024 83669709 13998390079
  Email:[EMAIL PROTECTED]
Website: http://www.neusoft.com 

 



----------------------------------------------------------------------------------------------
Confidentiality Notice: The information contained in this e-mail and any 
accompanying attachment(s) is intended only for the use of the intended 
recipient and may be confidential and/or privileged of Neusoft Group Ltd., its 
subsidiaries and/or its affiliates. If any reader of this communication is not 
the intended recipient, unauthorized use, forwarding, printing, storing, 
disclosure or copying is strictly prohibited, and may be unlawful. If you have 
received this communication in error, please immediately notify the sender by 
return e-mail, and delete the original message and all copies from your system. 
Thank you. 
-----------------------------------------------------------------------------------------------

Reply via email to