@Override public int write( ByteBuffer src ) throws IOException { return channel.write( src ); }
@Override public int read( ByteBuffer dst ) throws IOException { return channel.read( dst ); }
assert _chan != null; // chan set by incoming reader, since we KNOW it is a TCP ((SocketChannel)_chan).socket().getOutputStream().write(0xcd); int x = ((SocketChannel)_chan).socket().getInputStream().read(); try { _chan.close(); } catch( IOException ignore ) {} // Silently close _chan.close();
public void close() throws IOException { if (_channel.isOpen()) { try { if (_channel instanceof SocketChannel) { // TODO - is this really required? Socket socket= ((SocketChannel)_channel).socket(); try { socket.shutdownOutput(); } finally { socket.close(); } } } finally { _channel.close(); } } }
@Override public void shutdownOutput() { LOG.debug("oshut {}", this); _oshut = true; if (_channel.isOpen()) { try { if (!_socket.isOutputShutdown()) _socket.shutdownOutput(); } catch (IOException e) { LOG.debug(e); } finally { if (_ishut) { close(); } } } }
public void shutdownOutput() throws IOException { if (_channel.isOpen() && _channel instanceof SocketChannel) { Socket socket= ((SocketChannel)_channel).socket(); if (!socket.isClosed()&&!socket.isOutputShutdown()) socket.shutdownOutput(); } }
@Override public boolean isOutputShutdown() { return _oshut || !_channel.isOpen() || _socket.isOutputShutdown(); }
@Override public boolean isInputShutdown() { return _ishut || !_channel.isOpen() || _socket.isInputShutdown(); }
public void close() throws IOException { if (_socket!=null && !_socket.isOutputShutdown()) _socket.shutdownOutput(); _channel.close(); }
@Override public void doClose() { if (LOG.isDebugEnabled()) LOG.debug("doClose {}", this); try { _channel.close(); } catch (IOException e) { LOG.debug(e); } finally { super.doClose(); } }
@Override public void run() { try { if (getChannel().isOpen()) { int oldInterestOps = _key.interestOps(); int newInterestOps = _interestOps.get(); if (newInterestOps != oldInterestOps) setKeyInterests(oldInterestOps, newInterestOps); } } catch (CancelledKeyException x) { LOG.debug("Ignoring key update for concurrently closed channel {}", this); close(); } catch (Exception x) { LOG.warn("Ignoring key update for " + this, x); close(); } } };
@Override public int fill(ByteBuffer buffer) throws IOException { if (isInputShutdown()) return -1; int pos=BufferUtil.flipToFill(buffer); int filled; try { filled = _channel.read(buffer); if (filled>0) notIdle(); else if (filled==-1) shutdownInput(); } catch(IOException e) { LOG.debug(e); shutdownInput(); filled = -1; } finally { BufferUtil.flipToFlush(buffer,pos); } if (LOG.isDebugEnabled()) LOG.debug("filled {} {}", filled, BufferUtil.toDetailString(buffer)); return filled; }
@Override public int fill(ByteBuffer buffer) throws IOException { if (_ishut) return -1; int pos=BufferUtil.flipToFill(buffer); try { int filled = _channel.read(buffer); LOG.debug("filled {} {}", filled, this); if (filled>0) notIdle(); else if (filled==-1) shutdownInput(); return filled; } catch(IOException e) { LOG.debug(e); shutdownInput(); return -1; } finally { BufferUtil.flipToFlush(buffer,pos); } }
@Override public void close() throws IOException { channel.close(); }
int readBytes = -1; try { readBytes = socketChannel.read(len); } catch (IOException ignored) { readBytes = socketChannel.read(messageBytes); } catch (IOException e) { LoggerUtils.warnAndDebugDetails(logger, "unable to read data from {}", socketChannel, e); try { final Handshake craft = Handshake.craft(hs.getInfoHash(), myContext.getPeersStorage().getSelf().getPeerIdArray()); socketChannel.write(craft.getData()); } catch (IOException e) { LoggerUtils.warnAndDebugDetails(logger, "error in sending handshake to {}", socketChannel, e);
@Override public boolean isOpen() { return channel.isOpen(); }
@Override public void shutdownOutput() { LOG.debug("oshut {}", this); _oshut = true; if (_channel.isOpen()) { try { if (!_socket.isOutputShutdown()) _socket.shutdownOutput(); } catch (IOException e) { LOG.debug(e); } finally { if (_ishut) { close(); } } } }