https://issues.apache.org/bugzilla/show_bug.cgi?id=52072

[email protected] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|                            |All

--- Comment #1 from [email protected] 2011-10-22 08:06:36 UTC ---
I have created a temporary fix , at least it works for my case and let me pass
my stress test :)
Caveat: The actual timeout may be multiplied by the actual number of read
required in the extreme case.

public String read(InputStream is) {
        byte[] msg = new byte[0];
        int msgLen = 0;
        /* BEGFIX */
        int nleft = 0;
        int nread = 0;
        int offset = 0;
        /* ENDFIX */
        try {
            byte[] lengthBuffer = new byte[lengthPrefixLen];
            if (is.read(lengthBuffer, 0, lengthPrefixLen) == lengthPrefixLen) {
                msgLen = byteArrayToInt(lengthBuffer);
                msg = new byte[msgLen];
                /* BEGFIX
                int bytes = is.read(msg);
                if (bytes < msgLen){ 
                     log.warn("Incomplete message read, expected: "+msgLen+"
got: "+bytes);
                }
                ENDFIX */
                /* BEGFIX */
                nleft = msgLen;
                offset = 0;
                while (nleft > 0) {
                    nread = is.read(msg, offset, nleft);
                    nleft = nleft - nread;
                    offset = offset + nread;
                }
                /* ENDFIX */
            }
        } catch (SocketTimeoutException e) {
            // drop out to handle buffer
        } catch (InterruptedIOException e) {
            // drop out to handle buffer
        } catch (IOException e) {
            log.warn("Read error:" + e);
        }

        String buffer = JOrphanUtils.baToHexString(msg);
        log.debug("Read: " + msgLen + "\n" + buffer);
        return buffer;
    }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to