public void run()

in client/src/main/java/org/apache/qpid/transport/network/io/IoReceiver.java [142:235]


    public void run()
    {
        final int threshold = bufferSize / 2;

        // I set the read buffer size similar to SO_RCVBUF
        // Haven't tested with a lower value to see if it's better or worse
        byte[] buffer = new byte[bufferSize];
        try
        {
            InputStream in = socket.getInputStream();
            int read = 0;
            int offset = 0;
            long currentTime;
            while(read != -1)
            {
                try
                {
                    while ((read = in.read(buffer, offset, bufferSize-offset)) != -1)
                    {
                        if (read > 0)
                        {
                            ByteBuffer b = ByteBuffer.wrap(buffer,offset,read);
                            receiver.received(b);
                            offset+=read;
                            if (offset > threshold)
                            {
                                offset = 0;
                                buffer = new byte[bufferSize];
                            }
                        }
                        currentTime =  System.currentTimeMillis();

                        if(_ticker != null)
                        {
                            int tick = _ticker.getTimeToNextTick(currentTime);
                            if(tick <= 0)
                            {
                                tick = _ticker.tick(currentTime);
                            }
                            try
                            {
                                if(!socket.isClosed())
                                {
                                    socket.setSoTimeout(tick <= 0 ? 1 : tick);
                                }
                            }
                            catch(SocketException e)
                            {
                                // ignore - closed socket
                            }
                        }
                    }
                }
                catch (SocketTimeoutException e)
                {
                    currentTime = System.currentTimeMillis();
                    if(_ticker != null)
                    {
                        final int tick = _ticker.tick(currentTime);
                        if(!socket.isClosed())
                        {
                            try
                            {
                                socket.setSoTimeout(tick <= 0 ? 1 : tick );
                            }
                            catch(SocketException ex)
                            {
                                // ignore - closed socket
                            }
                        }
                    }
                }
            }
        }
        catch (Exception t)
        {
            if (shouldReport(t))
            {
                receiver.exception(t);
            }
        }
        finally
        {
            receiver.closed();
            try
            {
                socket.close();
            }
            catch(Exception e)
            {
                LOGGER.warn("Error closing socket", e);
            }
        }
    }