Code example for Socket

Methods: getSoTimeout, isClosed, isInputShutdown, isOutputShutdown, setSoTimeout

0
    protected boolean isStale() throws IOException { 
        boolean isStale = true;
        // BEGIN android-note 
        // The following line was expanded to check for input/output shutdown. 
        // END android-note 
        if (! (socket.isClosed() || socket.isInputShutdown()
                        || socket.isOutputShutdown())) {
            // the socket is open, but could still have been closed from the other end 
            isStale = false;
            try { 
                if (inputStream.available() <= 0) {
                    int soTimeout = socket.getSoTimeout();
                    try { 
                        socket.setSoTimeout(1);
                        inputStream.mark(1);
                        int byteRead = inputStream.read();
                        if (byteRead == -1) {
                            // again - if the socket is reporting all data read, 
                            // probably stale 
                            isStale = true;
                        } else { 
                            inputStream.reset();
                        } 
                    } finally { 
                        socket.setSoTimeout(soTimeout);
                    } 
                } 
            } catch (InterruptedIOException e) {
                if (!isSocketTimeoutException(e)) {
                    throw e;