public final InputStream getInputStream() throws IOException { InputStream local = inputStreamRef.get(); if (local != null) { return local; } local = getInputStream(socket); if (inputStreamRef.compareAndSet(null, local)) { return local; } return inputStreamRef.get(); }
public final OutputStream getOutputStream() throws IOException { OutputStream local = outputStreamRef.get(); if (local != null) { return local; } local = getOutputStream(socket); if (outputStreamRef.compareAndSet(null, local)) { return local; } return outputStreamRef.get(); }
@Override public SocketAddress getRemoteAddress() { final SocketHolder socketHolder = this.socketHolderRef.get(); return socketHolder != null ? socketHolder.getSocket().getRemoteSocketAddress() : null; }
private int fillInputBuffer(final int timeout) throws IOException { final SocketHolder socketHolder = ensureOpen(); final Socket socket = socketHolder.getSocket(); final int oldtimeout = socket.getSoTimeout(); try { socket.setSoTimeout(timeout); return this.inBuffer.fillBuffer(socketHolder.getInputStream()); } finally { socket.setSoTimeout(oldtimeout); } }
@Override public void close() throws IOException { final SocketHolder socketHolder = this.socketHolderRef.getAndSet(null); if (socketHolder != null) { try (final Socket socket = socketHolder.getSocket()) { this.inBuffer.clear(); this.outbuffer.flush(socketHolder.getOutputStream()); try { try { socket.shutdownOutput(); } catch (final IOException ignore) { } try { socket.shutdownInput(); } catch (final IOException ignore) { } } catch (final UnsupportedOperationException ignore) { // if one isn't supported, the other one isn't either } } } }
@Override public void bind(final Socket socket) throws IOException { super.bind(this.wireLog.isDebugEnabled() ? new LoggingSocketHolder(socket, this.id, this.wireLog) : new SocketHolder(socket)); socketTimeout = Timeout.ofMilliseconds(socket.getSoTimeout()); }
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return {@code true}. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); bind(new SocketHolder(socket)); }
private int fillInputBuffer(final int timeout) throws IOException { final SocketHolder socketHolder = ensureOpen(); final Socket socket = socketHolder.getSocket(); final int oldtimeout = socket.getSoTimeout(); try { socket.setSoTimeout(timeout); return this.inBuffer.fillBuffer(socketHolder.getInputStream()); } finally { socket.setSoTimeout(oldtimeout); } }
@Override public void close() throws IOException { final SocketHolder socketHolder = this.socketHolderRef.getAndSet(null); if (socketHolder != null) { try (final Socket socket = socketHolder.getSocket()) { this.inBuffer.clear(); this.outbuffer.flush(socketHolder.getOutputStream()); try { try { socket.shutdownOutput(); } catch (final IOException ignore) { } try { socket.shutdownInput(); } catch (final IOException ignore) { } } catch (final UnsupportedOperationException ignore) { // if one isn't supported, the other one isn't either } } } }
public final OutputStream getOutputStream() throws IOException { OutputStream local = outputStreamRef.get(); if (local != null) { return local; } local = getOutputStream(socket); if (outputStreamRef.compareAndSet(null, local)) { return local; } return outputStreamRef.get(); }
public final InputStream getInputStream() throws IOException { InputStream local = inputStreamRef.get(); if (local != null) { return local; } local = getInputStream(socket); if (inputStreamRef.compareAndSet(null, local)) { return local; } return inputStreamRef.get(); }
@Override public SocketAddress getLocalAddress() { final SocketHolder socketHolder = this.socketHolderRef.get(); return socketHolder != null ? socketHolder.getSocket().getLocalSocketAddress() : null; }
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return {@code true}. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); bind(new SocketHolder(socket)); }
@Override protected OutputStream getOutputStream(final Socket socket) throws IOException { return new LoggingOutputStream(super.getOutputStream(socket), wire); } }
@Override protected InputStream getInputStream(final Socket socket) throws IOException { return new LoggingInputStream(super.getInputStream(socket), wire); }
@Override public SocketAddress getLocalAddress() { final SocketHolder socketHolder = this.socketHolderRef.get(); return socketHolder != null ? socketHolder.getSocket().getLocalSocketAddress() : null; }
@Override public void bind(final Socket socket) throws IOException { super.bind(this.wire.isEnabled() ? new LoggingSocketHolder(socket, wire) : new SocketHolder(socket)); }
@Override protected OutputStream getOutputStream(final Socket socket) throws IOException { return new LoggingOutputStream(super.getOutputStream(socket), wire); } }
@Override protected InputStream getInputStream(final Socket socket) throws IOException { return new LoggingInputStream(super.getInputStream(socket), wire); }
@Override public SSLSession getSSLSession() { final SocketHolder socketHolder = this.socketHolderRef.get(); if (socketHolder != null) { final Socket socket = socketHolder.getSocket(); return socket instanceof SSLSocket ? ((SSLSocket) socket).getSession() : null; } return null; }