Java Code Examples for java.net.Socket.isInputShutdown()

The following are Jave code examples for showing how to use isInputShutdown() of the java.net.Socket class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: pcloud-networking-java   File: RealConnection.java   Source Code and License Vote up 5 votes
boolean isHealthy(boolean doExtensiveChecks) {
    if (!connected) {
        return false;
    }

    Socket socket;
    BufferedSource source;
    synchronized (this) {
        socket = this.socket;
        source = this.source;
    }
    if (socket == null ||
            source == null ||
            socket.isClosed() ||
            socket.isInputShutdown() ||
            socket.isOutputShutdown()) {
        return false;
    }

    if (doExtensiveChecks) {
        try {
            int readTimeout = socket.getSoTimeout();
            try {
                socket.setSoTimeout(1);
                return !source.exhausted();
            } finally {
                socket.setSoTimeout(readTimeout);
            }
        } catch (SocketTimeoutException ignored) {
            ignored.printStackTrace();
            // Read timed out; socket is good.
        } catch (IOException e) {
            return false; // Couldn't read; socket is closed.
        }
    }

    return true;
}
 
Example 2
Project: DreamSocket   File: DreamTCPSocket.java   Source Code and License Vote up 5 votes
private static void shutdownInput(Socket socket) {
    if (socket != null && !socket.isInputShutdown()) {
        try {
            LoggerFactory.getLogger().info("关闭Socket输入...");
            socket.shutdownInput();
        } catch (IOException e) {
            LoggerFactory.getLogger().error("关闭Socket输入异常", e);
        }
    }
}