@Override
	public void end() throws IOException {
		if (!isActive())
			return;
		
		log.info("Closing connection from {}", socket);
		
		if (!socket.isClosed())
			socket.close();
		if (target != null && !target.isClosed())
			target.close();
		getServer().unregisterConnection(this);
		this.terminated = true;

		log.info("Connection closed");
	}