private boolean writeToSocket (ByteBuffer buffer) throws IOException {
		SocketChannel socketChannel = this.socketChannel;
		if (socketChannel == null) throw new SocketException("Connection is closed.");

		while (buffer.hasRemaining()) {
			if (bufferPositionFix) {
				buffer.compact();
				buffer.flip();
			}
			if (socketChannel.write(buffer) == 0) break;
		}

		lastWriteTime = System.currentTimeMillis();
		return !buffer.hasRemaining();
	}