sun.net.ConnectionResetException Java Examples

The following examples show how to use sun.net.ConnectionResetException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractPlainSocketImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #2
Source File: AbstractPlainSocketImpl.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset then return 0 to indicate
     * there are no buffered bytes.
     */
    if (isConnectionReset()) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #3
Source File: AbstractPlainSocketImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #4
Source File: AbstractPlainSocketImpl.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset then return 0 to indicate
     * there are no buffered bytes.
     */
    if (isConnectionReset()) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #5
Source File: AbstractPlainSocketImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #6
Source File: AbstractPlainSocketImpl.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #7
Source File: AbstractPlainSocketImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #8
Source File: AbstractPlainSocketImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #9
Source File: AbstractPlainSocketImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #10
Source File: AbstractPlainSocketImpl.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #11
Source File: AbstractPlainSocketImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #12
Source File: AbstractPlainSocketImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #13
Source File: SocketChannelImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public int read(ByteBuffer buf) throws IOException {
    Objects.requireNonNull(buf);

    readLock.lock();
    try {
        boolean blocking = isBlocking();
        int n = 0;
        try {
            beginRead(blocking);

            // check if connection has been reset
            if (connectionReset)
                throwConnectionReset();

            // check if input is shutdown
            if (isInputClosed)
                return IOStatus.EOF;

            n = IOUtil.read(fd, buf, -1, nd);
            if (blocking) {
                while (IOStatus.okayToRetry(n) && isOpen()) {
                    park(Net.POLLIN);
                    n = IOUtil.read(fd, buf, -1, nd);
                }
            }
        } catch (ConnectionResetException e) {
            connectionReset = true;
            throwConnectionReset();
        } finally {
            endRead(blocking, n > 0);
            if (n <= 0 && isInputClosed)
                return IOStatus.EOF;
        }
        return IOStatus.normalize(n);
    } finally {
        readLock.unlock();
    }
}
 
Example #14
Source File: AbstractPlainSocketImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
    } catch (ConnectionResetException exc1) {
        setConnectionReset();
    }
    return n;
}
 
Example #15
Source File: AbstractPlainSocketImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #16
Source File: AbstractPlainSocketImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #17
Source File: AbstractPlainSocketImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #18
Source File: AbstractPlainSocketImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #19
Source File: AbstractPlainSocketImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #20
Source File: AbstractPlainSocketImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of bytes that can be read without blocking.
 */
protected synchronized int available() throws IOException {
    if (isClosedOrPending()) {
        throw new IOException("Stream closed.");
    }

    /*
     * If connection has been reset or shut down for input, then return 0
     * to indicate there are no buffered bytes.
     */
    if (isConnectionReset() || shut_rd) {
        return 0;
    }

    /*
     * If no bytes available and we were previously notified
     * of a connection reset then we move to the reset state.
     *
     * If are notified of a connection reset then check
     * again if there are bytes buffered on the socket.
     */
    int n = 0;
    try {
        n = socketAvailable();
        if (n == 0 && isConnectionResetPending()) {
            setConnectionReset();
        }
    } catch (ConnectionResetException exc1) {
        setConnectionResetPending();
        try {
            n = socketAvailable();
            if (n == 0) {
                setConnectionReset();
            }
        } catch (ConnectionResetException exc2) {
        }
    }
    return n;
}
 
Example #21
Source File: SocketChannelImpl.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public long read(ByteBuffer[] dsts, int offset, int length)
    throws IOException
{
    Objects.checkFromIndexSize(offset, length, dsts.length);

    readLock.lock();
    try {
        boolean blocking = isBlocking();
        long n = 0;
        try {
            beginRead(blocking);

            // check if connection has been reset
            if (connectionReset)
                throwConnectionReset();

            // check if input is shutdown
            if (isInputClosed)
                return IOStatus.EOF;

            n = IOUtil.read(fd, dsts, offset, length, nd);
            if (blocking) {
                while (IOStatus.okayToRetry(n) && isOpen()) {
                    park(Net.POLLIN);
                    n = IOUtil.read(fd, dsts, offset, length, nd);
                }
            }
        } catch (ConnectionResetException e) {
            connectionReset = true;
            throwConnectionReset();
        } finally {
            endRead(blocking, n > 0);
            if (n <= 0 && isInputClosed)
                return IOStatus.EOF;
        }
        return IOStatus.normalize(n);
    } finally {
        readLock.unlock();
    }
}
 
Example #22
Source File: SocketInputStream.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
int read(byte b[], int off, int length, int timeout) throws IOException {
    int n;

    // EOF already encountered
    if (eof) {
        return -1;
    }

    // connection reset
    if (impl.isConnectionReset()) {
        throw new SocketException("Connection reset");
    }

    // bounds check
    if (length <= 0 || off < 0 || length > b.length - off) {
        if (length == 0) {
            return 0;
        }
        throw new ArrayIndexOutOfBoundsException("length == " + length
                + " off == " + off + " buffer length == " + b.length);
    }

    // acquire file descriptor and do the read
    FileDescriptor fd = impl.acquireFD();
    try {
        n = socketRead(fd, b, off, length, timeout);
        if (n > 0) {
            return n;
        }
    } catch (ConnectionResetException rstExc) {
        impl.setConnectionReset();
    } finally {
        impl.releaseFD();
    }

    /*
     * If we get here we are at EOF, the socket has been closed,
     * or the connection has been reset.
     */
    if (impl.isClosedOrPending()) {
        throw new SocketException("Socket closed");
    }
    if (impl.isConnectionReset()) {
        throw new SocketException("Connection reset");
    }
    eof = true;
    return -1;
}