/** * If we succeed to write everything in writeBuffer, client write is finished => invoke * writeCallback */ private void doWrite() { int written = 0; try { if (((SocketChannel) channel).isConnected()) { written = ((SocketChannel) channel).write(ByteBuffer.wrap(writeBuffer.toString().getBytes())); } } catch (IOException e) { logger.error("IOException during write: {}", e.getMessage()); invokeCloseCallback(); Closeables.closeQuietly(channel); } writeBuffer.delete(0, written); logger.debug("wrote: {} bytes", written); logger.debug("writeBuffer size: {}", writeBuffer.length()); if (writeBuffer.length() > 0) { IOLoop.INSTANCE.updateHandler(channel, interestOps |= SelectionKey.OP_WRITE); } else { IOLoop.INSTANCE.updateHandler(channel, interestOps &= ~SelectionKey.OP_WRITE); invokeWriteCallback(); } }
/** Close the socket. */ public void close() { Closeables.closeQuietly(channel); invokeCloseCallback(); }