text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
	include_once(dirname(__FILE__)."/../../lib/session_manager.php");
	include_once(dirname(__FILE__)."/../../lib/site_config.php");
	include_once(dirname(__FILE__)."/../../lib/utils.php");
	include_once(dirname(__FILE__)."/../../database/config.php");
	$page_id = CSiteConfig::HF_FAQ;
	$login = CSessionManager::Get(CSessionManager::BOOL_LOGIN);
?>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Terms of Contribution</title>

		<link rel="stylesheet" type="text/css" href="../../css/mipcat.css" />
		<link rel="stylesheet" type="text/css" href="../../3rd_party/bootstrap/css/bootstrap.css" />

		<?php
			include(dirname(__FILE__)."/../../lib/header.php");
		?>

Terms of Contribution

			By using the <?php echo(CConfig::SNC_SITE_NAME);?>.com contributor feature, contributor agrees to comply with all of the terms and conditions hereof. The right to use the <?php echo(CConfig::SNC_SITE_NAME);?>.com is personal to contributor and is not transferable to any other person or entity. Contributor is responsible for all of the data/information uploaded to Contributor's Account (under any screen name or password) and for ensuring that all use of Contributor's Account complies fully with the provisions of this Agreement. Contributor(s) shall be responsible for protecting the confidentiality of thier password(s).

			The Mastishka Intellisys Private Limited, parent company (owner) of the <?php echo(CConfig::SNC_SITE_NAME);?>.com shall have the right at any time to change or discontinue any aspect or feature of <?php echo(CConfig::SNC_SITE_NAME);?>.com, including, but not limited to, content, hours of availability payment module.

			The Mastishka Intellisys Pvt LTD shall have the right at any time to change or modify the terms and conditions applicable to Contributor's use of the <?php echo(CConfig::SNC_SITE_NAME);?>.com, or any part thereof, or to impose new conditions, including but not limited to, adding fees and charges for use.

			Such changes, modifications, additions or deletions shall be effective immediately upon notice thereof, which may be given by means including but not limited to, posting on <?php echo(CConfig::SNC_SITE_NAME);?>.com, or by electronic or conventional mail, or by any other means by which Contributor obtains notice thereof. Any use of the <?php echo(CConfig::SNC_SITE_NAME);?>.com by Contributor after such notice shall be deemed to constitute acceptance by Contributor of such changes, modifications or additions.

			Following are the Terms and conditions for contribution in <?php echo(CConfig::SNC_SITE_NAME);?>.com knowledgebase:

Uploading a question/test does not mean that you have earned point. The point will be reflected only when question/test is veryfied and accepted by <?php echo(CConfig::SNC_SITE_NAME);?> team.

Our test model is dynamic so we won't take any responsiblity that your question will apear in any institute/corporate test. It may or may not.

The <?php echo(CConfig::SNC_SITE_NAME);?> knowledge base is sole property of <?php echo(CConfig::SNC_SITE_NAME);?>.

Accepting your Contribution is sole discretion of <?php echo(CConfig::SNC_SITE_NAME);?>.

Tentetive time of questions varification is 30 days, how ever it may be increased as per actuall flow of questions per day.

By opening contributor account you are accepting that you are going to contribute in <?php echo(CConfig::SNC_SITE_NAME);?> knowledge base, however, <?php echo(CConfig::SNC_SITE_NAME);?> knowledge base is sole property of <?php echo(CConfig::SNC_SITE_NAME);?>.

After varification, if we found that your question already exist in the <?php echo(CConfig::SNC_SITE_NAME);?> database than it won't be accepted by <?php echo(CConfig::SNC_SITE_NAME);?>.com.

Any disputes can be resolved under Indore's (Madhya Pradesh, India) juridiction only.


text:
package com.chr.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Service;

import com.chr.domain.User;
import com.chr.service.UserOperationsService;

/**
 * @author Edwin Chen
 *
 */
@Service
public class UserOperationsServiceImpl implements UserOperationsService {
	@Autowired
	private RedisTemplate redisTemplate;

	@Override
	public void add(User user) {
		// TODO Auto-generated method stub
		/*
		 * boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
		 * public Boolean doInRedis(RedisConnection redisConnection) throws
		 * DataAccessException { RedisSerializer<String> redisSerializer =
		 * redisTemplate .getStringSerializer(); byte[] key =
		 * redisSerializer.serialize(user.getId()); byte[] value =
		 * redisSerializer.serialize(user.getName()); return
		 * redisConnection.setNX(key, value); } }); return result;
		 */
		ValueOperations<String, User> valueops = redisTemplate
				.opsForValue();
		valueops.set(user.getId(), user);
	}

	@Override
	public User getUser(String key) {
		ValueOperations<String, User> valueops = redisTemplate
				.opsForValue();
		User user = valueops.get(key);
		return user;
	}

}

redpajama_set_name: RedPajamaGithub


text:
// Copyright 2014 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.skyframe;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.devtools.build.lib.actions.FilesetTraversalParams.PackageBoundaryMode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalFunction.DanglingSymlinkException;
import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalFunction.FileType;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.LegacySkyKey;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

/**
 * Collection of files found while recursively traversing a path.
 *
 *
The path may refer to files, symlinks or directories that may or may not exist.
 *
 *
Traversing a file or a symlink results in a single {@link ResolvedFile} corresponding to the
 * file or symlink.
 *
 *
Traversing a directory results in a collection of {@link ResolvedFile}s for all files and
 * symlinks under it, and in all of its subdirectories. The {@link TraversalRequest} can specify
 * whether to traverse source subdirectories that are packages (have BUILD files in them).
 *
 *
Traversing a symlink that points to a directory is the same as traversing a normal directory.
 * The paths in the result will not be resolved; the files will be listed under the symlink, as if
 * it was the actual directory they reside in.
 *
 *
Editing a file that is part of this traversal, or adding or removing a file in a directory
 * that is part of this traversal, will invalidate this {@link SkyValue}. This also applies to
 * directories that are symlinked to.
 */
public final class RecursiveFilesystemTraversalValue implements SkyValue {
  static final RecursiveFilesystemTraversalValue EMPTY = new RecursiveFilesystemTraversalValue(
      Optional.<ResolvedFile>absent(),
      NestedSetBuilder.<ResolvedFile>emptySet(Order.STABLE_ORDER));

  /** The root of the traversal. May only be absent for the {@link #EMPTY} instance. */
  private final Optional<ResolvedFile> resolvedRoot;

  /** The transitive closure of {@link ResolvedFile}s. */
  private final NestedSet<ResolvedFile> resolvedPaths;

  private RecursiveFilesystemTraversalValue(Optional<ResolvedFile> resolvedRoot,
      NestedSet<ResolvedFile> resolvedPaths) {
    this.resolvedRoot = Preconditions.checkNotNull(resolvedRoot);
    this.resolvedPaths = Preconditions.checkNotNull(resolvedPaths);
  }

  static RecursiveFilesystemTraversalValue of(ResolvedFile resolvedRoot,
      NestedSet<ResolvedFile> resolvedPaths) {
    if (resolvedPaths.isEmpty()) {
      return EMPTY;
    } else {
      return new RecursiveFilesystemTraversalValue(Optional.of(resolvedRoot), resolvedPaths);
    }
  }

  static RecursiveFilesystemTraversalValue of(ResolvedFile singleMember) {
    return new RecursiveFilesystemTraversalValue(Optional.of(singleMember),
        NestedSetBuilder.<ResolvedFile>create(Order.STABLE_ORDER, singleMember));
  }

  /** Returns the root of the traversal; absent only for the {@link #EMPTY} instance. */
  public Optional<ResolvedFile> getResolvedRoot() {
    return resolvedRoot;
  }

  /**
   * Retrieves the set of {@link ResolvedFile}s that were found by this traversal.
   *
   *
The returned set may be empty if no files were found, or the ones found were to be
   * considered non-existent. Unless it's empty, the returned set always includes the
   * {@link #getResolvedRoot() resolved root}.
   *
   *
The returned set also includes symlinks. If a symlink points to a directory, its contents
   * are also included in this set, and their path will start with the symlink's path, just like on
   * a usual Unix file system.
   */
  public NestedSet<ResolvedFile> getTransitiveFiles() {
    return resolvedPaths;
  }

  public static SkyKey key(TraversalRequest traversal) {
    return LegacySkyKey.create(SkyFunctions.RECURSIVE_FILESYSTEM_TRAVERSAL, traversal);
  }

  /** The parameters of a file or directory traversal. */
  public static final class TraversalRequest {

    /** The path to start the traversal from; may be a file, a directory or a symlink. */
    final RootedPath path;

    /**
     * Whether the path is in the output tree.
     *
     *
Such paths and all their subdirectories are assumed not to define packages, so package
     * lookup for them is skipped.
     */
    final boolean isGenerated;

    /** Whether traversal should descend into directories that are roots of subpackages. */
    final PackageBoundaryMode crossPkgBoundaries;

    /**
     * Whether to skip checking if the root (if it's a directory) contains a BUILD file.
     *
     *
Such directories are not considered to be packages when this flag is true. This needs to
     * be true in order to traverse directories of packages, but should be false for their
     * subdirectories.
     */
    final boolean skipTestingForSubpackage;

    /** A pattern that files must match to be included in this traversal (may be null.) */
    @Nullable
    final Pattern pattern;

    /** Information to be attached to any error messages that may be reported. */
    @Nullable final String errorInfo;

    public TraversalRequest(RootedPath path, boolean isRootGenerated,
        PackageBoundaryMode crossPkgBoundaries, boolean skipTestingForSubpackage,
        @Nullable String errorInfo, @Nullable Pattern pattern) {
      this.path = path;
      this.isGenerated = isRootGenerated;
      this.crossPkgBoundaries = crossPkgBoundaries;
      this.skipTestingForSubpackage = skipTestingForSubpackage;
      this.errorInfo = errorInfo;
      this.pattern = pattern;
    }

    private TraversalRequest duplicate(RootedPath newRoot, boolean newSkipTestingForSubpackage) {
      return new TraversalRequest(newRoot, isGenerated, crossPkgBoundaries,
          newSkipTestingForSubpackage, errorInfo, pattern);
    }

    /** Creates a new request to traverse a child element in the current directory (the root). */
    TraversalRequest forChildEntry(RootedPath newPath) {
      return duplicate(newPath, false);
    }

    /**
     * Creates a new request for a changed root.
     *
     *
This method can be used when a package is found out to be under a different root path than
     * originally assumed.
     */
    TraversalRequest forChangedRootPath(Path newRoot) {
      return duplicate(RootedPath.toRootedPath(newRoot, path.getRelativePath()),
          skipTestingForSubpackage);
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (!(obj instanceof TraversalRequest)) {
        return false;
      }
      TraversalRequest o = (TraversalRequest) obj;
      return path.equals(o.path) && isGenerated == o.isGenerated
          && crossPkgBoundaries == o.crossPkgBoundaries
          && skipTestingForSubpackage == o.skipTestingForSubpackage
          && Objects.equal(pattern, o.pattern);
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(path, isGenerated, crossPkgBoundaries, skipTestingForSubpackage,
          pattern);
    }

    @Override
    public String toString() {
      return String.format(
          "TraversalParams(root=%s, is_generated=%d, skip_testing_for_subpkg=%d,"
          + " pkg_boundaries=%s, pattern=%s)", path, isGenerated ? 1 : 0,
          skipTestingForSubpackage ? 1 : 0, crossPkgBoundaries,
          pattern == null ? "null" : pattern.pattern());
    }
  }

  private static final class Symlink {
    private final RootedPath linkName;
    private final PathFragment unresolvedLinkTarget;
    // The resolved link target is returned by ResolvedFile.getPath()

    private Symlink(RootedPath linkName, PathFragment unresolvedLinkTarget) {
      this.linkName = Preconditions.checkNotNull(linkName);
      this.unresolvedLinkTarget = Preconditions.checkNotNull(unresolvedLinkTarget);
    }

    PathFragment getNameInSymlinkTree() {
      return linkName.getRelativePath();
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (!(obj instanceof Symlink)) {
        return false;
      }
      Symlink o = (Symlink) obj;
      return linkName.equals(o.linkName) && unresolvedLinkTarget.equals(o.unresolvedLinkTarget);
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(linkName, unresolvedLinkTarget);
    }

    @Override
    public String toString() {
      return String.format("Symlink(link_name=%s, unresolved_target=%s)",
          linkName, unresolvedLinkTarget);
    }
  }

  private static final class RegularFile implements ResolvedFile {
    private final RootedPath path;
    @Nullable private final FileStateValue metadata;

    /** C'tor for {@link #stripMetadataForTesting()}. */
    private RegularFile(RootedPath path) {
      this.path = Preconditions.checkNotNull(path);
      this.metadata = null;
    }

    RegularFile(RootedPath path, FileStateValue metadata) {
      this.path = Preconditions.checkNotNull(path);
      this.metadata = Preconditions.checkNotNull(metadata);
    }

    @Override
    public FileType getType() {
      return FileType.FILE;
    }

    @Override
    public RootedPath getPath() {
      return path;
    }

    @Override
    @Nullable
    public int getMetadataHash() {
      return metadata == null ? 0 : metadata.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (!(obj instanceof RegularFile)) {
        return false;
      }
      return this.path.equals(((RegularFile) obj).path)
          && Objects.equal(this.metadata, ((RegularFile) obj).metadata);
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(path, metadata);
    }

    @Override
    public String toString() {
      return String.format("RegularFile(path=%s)", path);
    }

    @Override
    public ResolvedFile stripMetadataForTesting() {
      return new RegularFile(path);
    }

    @Override
    public PathFragment getNameInSymlinkTree() {
      return path.getRelativePath();
    }

    @Override
    public PathFragment getTargetInSymlinkTree(boolean followSymlinks) {
      return path.asPath().asFragment();
    }
  }

  private static final class Directory implements ResolvedFile {
    private final RootedPath path;

    Directory(RootedPath path) {
      this.path = Preconditions.checkNotNull(path);
    }

    @Override
    public FileType getType() {
      return FileType.DIRECTORY;
    }

    @Override
    public RootedPath getPath() {
      return path;
    }

    @Override
    public int getMetadataHash() {
      return FileStateValue.DIRECTORY_FILE_STATE_NODE.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (!(obj instanceof Directory)) {
        return false;
      }
      return this.path.equals(((Directory) obj).path);
    }

    @Override
    public int hashCode() {
      return path.hashCode();
    }

    @Override
    public String toString() {
      return String.format("Directory(path=%s)", path);
    }

    @Override
    public ResolvedFile stripMetadataForTesting() {
      return this;
    }

    @Override
    public PathFragment getNameInSymlinkTree() {
      return path.getRelativePath();
    }

    @Override
    public PathFragment getTargetInSymlinkTree(boolean followSymlinks) {
      return path.asPath().asFragment();
    }
  }

  private static final class DanglingSymlink implements ResolvedFile {
    private final Symlink symlink;
    @Nullable private final FileStateValue metadata;

    private DanglingSymlink(Symlink symlink) {
      this.symlink = symlink;
      this.metadata = null;
    }

    private DanglingSymlink(RootedPath linkNamePath, PathFragment linkTargetPath) {
      this.symlink = new Symlink(linkNamePath, linkTargetPath);
      this.metadata = null;
    }

    DanglingSymlink(RootedPath linkNamePath, PathFragment linkTargetPath,
        FileStateValue metadata) {
      this.symlink = new Symlink(linkNamePath, linkTargetPath);
      this.metadata = Preconditions.checkNotNull(metadata);
    }

    @Override
    public FileType getType() {
      return FileType.DANGLING_SYMLINK;
    }

    @Override
    @Nullable
    public RootedPath getPath() {
      return null;
    }

    @Override
    @Nullable
    public int getMetadataHash() {
      return metadata == null ? 0 : metadata.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (!(obj instanceof DanglingSymlink)) {
        return false;
      }
      return Objects.equal(this.metadata, ((DanglingSymlink) obj).metadata)
          && this.symlink.equals(((DanglingSymlink) obj).symlink);
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(metadata, symlink);
    }

    @Override
    public String toString() {
      return String.format("DanglingSymlink(%s)", symlink);
    }

    @Override
    public ResolvedFile stripMetadataForTesting() {
      return new DanglingSymlink(symlink);
    }

    @Override
    public PathFragment getNameInSymlinkTree() {
      return symlink.getNameInSymlinkTree();
    }

    @Override
    public PathFragment getTargetInSymlinkTree(boolean followSymlinks)
        throws DanglingSymlinkException {
      if (followSymlinks) {
        throw new DanglingSymlinkException(symlink.linkName.asPath().getPathString(),
            symlink.unresolvedLinkTarget.getPathString());
      } else {
        return symlink.unresolvedLinkTarget;
      }
    }
  }

  private static final class SymlinkToFile implements ResolvedFile {
    private final RootedPath path;
    @Nullable private final FileStateValue metadata;
    private final Symlink symlink;

    /** C'tor for {@link #stripMetadataForTesting()}. */
    private SymlinkToFile(RootedPath targetPath, Symlink symlink) {
      this.path = Preconditions.checkNotNull(targetPath);
      this.metadata = null;
      this.symlink = Preconditions.checkNotNull(symlink);
    }

    private SymlinkToFile(
        RootedPath targetPath, RootedPath linkNamePath, PathFragment linkTargetPath) {
      this.path = Preconditions.checkNotNull(targetPath);
      this.metadata = null;
      this.symlink = new Symlink(linkNamePath, linkTargetPath);
    }

    SymlinkToFile(RootedPath targetPath, RootedPath linkNamePath,
        PathFragment linkTargetPath, FileStateValue metadata) {
      this.path = Preconditions.checkNotNull(targetPath);
      this.metadata = Preconditions.checkNotNull(metadata);
      this.symlink = new Symlink(linkNamePath, linkTargetPath);
    }

    @Override
    public FileType getType() {
      return FileType.SYMLINK_TO_FILE;
    }

    @Override
    public RootedPath getPath() {
      return path;
    }

    @Override
    @Nullable
    public int getMetadataHash() {
      return metadata == null ? 0 : metadata.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (!(obj instanceof SymlinkToFile)) {
        return false;
      }
      return this.path.equals(((SymlinkToFile) obj).path)
          && Objects.equal(this.metadata, ((SymlinkToFile) obj).metadata)
          && this.symlink.equals(((SymlinkToFile) obj).symlink);
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(path, metadata, symlink);
    }

    @Override
    public String toString() {
      return String.format("SymlinkToFile(target=%s, %s)", path, symlink);
    }

    @Override
    public ResolvedFile stripMetadataForTesting() {
      return new SymlinkToFile(path, symlink);
    }

    @Override
    public PathFragment getNameInSymlinkTree() {
      return symlink.getNameInSymlinkTree();
    }

    @Override
    public PathFragment getTargetInSymlinkTree(boolean followSymlinks) {
      return followSymlinks ? path.asPath().asFragment() : symlink.unresolvedLinkTarget;
    }
  }

  private static final class SymlinkToDirectory implements ResolvedFile {
    private final RootedPath path;
    @Nullable private final int metadataHash;
    private final Symlink symlink;

    /** C'tor for {@link #stripMetadataForTesting()}. */
    private SymlinkToDirectory(RootedPath targetPath, Symlink symlink) {
      this.path = Preconditions.checkNotNull(targetPath);
      this.metadataHash = 0;
      this.symlink = symlink;
    }

    private SymlinkToDirectory(
        RootedPath targetPath, RootedPath linkNamePath, PathFragment linkValue) {
      this.path = Preconditions.checkNotNull(targetPath);
      this.metadataHash = 0;
      this.symlink = new Symlink(linkNamePath, linkValue);
    }

    SymlinkToDirectory(RootedPath targetPath, RootedPath linkNamePath,
        PathFragment linkValue, int metadataHash) {
      this.path = Preconditions.checkNotNull(targetPath);
      this.metadataHash = metadataHash;
      this.symlink = new Symlink(linkNamePath, linkValue);
    }

    @Override
    public FileType getType() {
      return FileType.SYMLINK_TO_DIRECTORY;
    }

    @Override
    public RootedPath getPath() {
      return path;
    }

    @Override
    @Nullable
    public int getMetadataHash() {
      return metadataHash;
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      }
      if (!(obj instanceof SymlinkToDirectory)) {
        return false;
      }
      return this.path.equals(((SymlinkToDirectory) obj).path)
          && Objects.equal(this.metadataHash, ((SymlinkToDirectory) obj).metadataHash)
          && this.symlink.equals(((SymlinkToDirectory) obj).symlink);
    }

    @Override
    public int hashCode() {
      return Objects.hashCode(path, metadataHash, symlink);
    }

    @Override
    public String toString() {
      return String.format("SymlinkToDirectory(target=%s, %s)", path, symlink);
    }

    @Override
    public ResolvedFile stripMetadataForTesting() {
      return new SymlinkToDirectory(path, symlink);
    }

    @Override
    public PathFragment getNameInSymlinkTree() {
      return symlink.getNameInSymlinkTree();
    }

    @Override
    public PathFragment getTargetInSymlinkTree(boolean followSymlinks) {
      return followSymlinks ? path.asPath().asFragment() : symlink.unresolvedLinkTarget;
    }
  }

  static final class ResolvedFileFactory {
    private ResolvedFileFactory() {}

    public static ResolvedFile regularFile(RootedPath path, FileStateValue metadata) {
      return new RegularFile(path, metadata);
    }

    public static ResolvedFile directory(RootedPath path) {
      return new Directory(path);
    }

    public static ResolvedFile symlinkToFile(RootedPath targetPath, RootedPath linkNamePath,
        PathFragment linkTargetPath, FileStateValue metadata) {
      return new SymlinkToFile(targetPath, linkNamePath, linkTargetPath, metadata);
    }

    public static ResolvedFile symlinkToDirectory(RootedPath targetPath,
        RootedPath linkNamePath, PathFragment linkValue, int metadataHash) {
      return new SymlinkToDirectory(targetPath, linkNamePath, linkValue, metadataHash);
    }

    public static ResolvedFile danglingSymlink(RootedPath linkNamePath, PathFragment linkValue,
        FileStateValue metadata) {
      return new DanglingSymlink(linkNamePath, linkValue, metadata);
    }
  }

  @VisibleForTesting
  static final class ResolvedFileFactoryForTesting {
    private ResolvedFileFactoryForTesting() {}

    static ResolvedFile regularFileForTesting(RootedPath path) {
      return new RegularFile(path);
    }

    static ResolvedFile symlinkToFileForTesting(
        RootedPath targetPath, RootedPath linkNamePath, PathFragment linkTargetPath) {
      return new SymlinkToFile(targetPath, linkNamePath, linkTargetPath);
    }

    static ResolvedFile symlinkToDirectoryForTesting(
        RootedPath targetPath, RootedPath linkNamePath, PathFragment linkValue) {
      return new SymlinkToDirectory(targetPath, linkNamePath, linkValue);
    }

    public static ResolvedFile danglingSymlinkForTesting(
        RootedPath linkNamePath, PathFragment linkValue) {
      return new DanglingSymlink(linkNamePath, linkValue);
    }
  }

  /**
   * Path and type information about a single file or symlink.
   *
   *
The object stores things such as the absolute path of the file or symlink, its exact type
   * and, if it's a symlink, the resolved and unresolved link target paths.
   */
  public static interface ResolvedFile {
    /** Type of the entity under {@link #getPath()}. */
    FileType getType();

    /**
     * Path of the file, directory or resolved target of the symlink.
     *
     *
May only return null for dangling symlinks.
     */
    @Nullable
    RootedPath getPath();

    /**
     * Hash code of associated metadata.
     *
     *
This is usually some hash of the {@link FileStateValue} of the underlying filesystem
     * entity.
     *
     *
If tests stripped the metadata or the {@link ResolvedFile} was created by the
     * {@link ResolvedFileFactoryForTesting}, this method returns 0.
     */
    int getMetadataHash();

    /**
     * Returns the path of the Fileset-output symlink relative to the output directory.
     *
     *
The path should contain the FilesetEntry-specific destination directory (if any) and
     * should have necessary prefixes stripped (if any).
     */
    PathFragment getNameInSymlinkTree();

    /**
     * Returns the path of the symlink target.
     *
     * @throws DanglingSymlinkException if the target cannot be resolved because the symlink is
     *     dangling
     */
    PathFragment getTargetInSymlinkTree(boolean followSymlinks) throws DanglingSymlinkException;

    /**
     * Returns a copy of this object with the metadata stripped away.
     *
     *
This method should only be used by tests that wish to assert that this
     * {@link ResolvedFile} refers to the expected absolute path and has the expected type, without
     * asserting its actual contents (which the metadata is a function of).
     */
    @VisibleForTesting
    ResolvedFile stripMetadataForTesting();
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (!(obj instanceof RecursiveFilesystemTraversalValue)) {
      return false;
    }
    RecursiveFilesystemTraversalValue o = (RecursiveFilesystemTraversalValue) obj;
    return resolvedRoot.equals(o.resolvedRoot) && resolvedPaths.equals(o.resolvedPaths);
  }

  @Override
  public int hashCode() {
    return Objects.hashCode(resolvedRoot, resolvedPaths);
  }
}


text:
<!DOCTYPE html>

This test requires the Ahem font. It tests that dynamically set shape-insides should affect their block's children. You should see two green squares inside blue outlines.

XX

XX

XX

XX


text:
package org.nbone.persistence.exception;

/**
 * @author uap
 * @author thinking
 * @version 1.0
 */
public class PersistencePaginationException extends PersistenceBaseRuntimeException  {

	private static final long serialVersionUID = -7701596312811499374L;

	public PersistencePaginationException() {
		super();
	}

	public PersistencePaginationException(String message, Throwable cause) {
		super(message, cause);
	}

	public PersistencePaginationException(String message) {
		super(message);
	}

	public PersistencePaginationException(Throwable cause) {
		super(cause);
	}

}


text:
/*
Author: Georges-Antoine Assi
Repo: https://github.com/DrShavargo/animal-card-game
*/

#include <string>
#include <iostream>
#include <vector>
#include "AnimalCard.h"
using namespace std;

AnimalCard::AnimalCard(char tl, char tr, char br, char bl){
	_tl = tl;
	_tr = tr;
	_br = br;
	_bl = bl;
}

void AnimalCard::setOrientation(Orientation orientation){
	_orientation = orientation;
}

void AnimalCard::setRow(EvenOdd evenOdd){
	_evenOdd = evenOdd;
}

void AnimalCard::printRow(EvenOdd evenOdd){
	if (evenOdd == ODD){
		cout << " " << _tl << _tr;
	}
	else{
		cout << " " << _bl << _br;
	}
}

NoSplit::NoSplit(char c) : AnimalCard(c, c, c, c){}

SplitTwo::SplitTwo(char t, char b, Split split = HORIZONTAL) : AnimalCard(t, t, b, b){
	if (split == VERTICAL){
		_tr = b;
		_bl = t;
	}
}

SplitThree::SplitThree(char t, char l, char r, Split split = HORIZONTAL) : AnimalCard(t, t, r, l){
	if (split == VERTICAL){
		_tr = l;
		_bl = t;
	}
}

SplitFour::SplitFour(char a, char b, char c, char d) : AnimalCard(a, b, c, d){}

Joker::Joker(char type) : NoSplit(type){}

StartCard::StartCard() : NoSplit('c'){};


text:
/* $FreeBSD: src/sys/rpc/rpcclnt.c,v 1.3.2.1 2004/01/26 04:38:17 scottl Exp $ */
/* $Id: rpcclnt.c,v 1.9 2003/11/05 14:59:03 rees Exp $ */

/*
 * copyright (c) 2003
 * the regents of the university of michigan
 * all rights reserved
 *
 * permission is granted to use, copy, create derivative works and redistribute
 * this software and such derivative works for any purpose, so long as the name
 * of the university of michigan is not used in any advertising or publicity
 * pertaining to the use or distribution of this software without specific,
 * written prior authorization.  if the above copyright notice or any other
 * identification of the university of michigan is included in any copy of any
 * portion of this software, then the disclaimer below must also be included.
 *
 * this software is provided as is, without representation from the university
 * of michigan as to its fitness for any purpose, and without warranty by the
 * university of michigan of any kind, either express or implied, including
 * without limitation the implied warranties of merchantability and fitness for
 * a particular purpose. the regents of the university of michigan shall not be
 * liable for any damages, including special, indirect, incidental, or
 * consequential damages, with respect to any claim arising out of or in
 * connection with the use of the software, even if it has been or is hereafter
 * advised of the possibility of such damages.
 */

/*
 * Copyright (c) 1989, 1991, 1993, 1995 The Regents of the University of
 * California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by Rick Macklem at
 * The University of Guelph.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer. 2.
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution. 3. All advertising
 * materials mentioning features or use of this software must display the
 * following acknowledgement: This product includes software developed by the
 * University of California, Berkeley and its contributors. 4. Neither the
 * name of the University nor the names of its contributors may be used to
 * endorse or promote products derived from this software without specific
 * prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * @(#)nfs_socket.c	8.5 (Berkeley) 3/30/95
 */

/* XXX: kill ugly debug strings */
/* XXX: get rid of proct, as it is not even being used... (or keep it so v{2,3}
 *      can run, but clean it up! */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/mount.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/syslog.h>
#include <sys/malloc.h>
#include <sys/uio.h>
#include <sys/lock.h>
#include <sys/signalvar.h>
#include <sys/sysent.h>
#include <sys/syscall.h>
#include <sys/sysctl.h>

#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/mutex.h>

#include <netinet/in.h>
#include <netinet/tcp.h>

#include <nfs/rpcv2.h>

#include <rpc/rpcm_subs.h>
#include <rpc/rpcclnt.h>

/* memory management */
#ifdef __OpenBSD__
struct pool     rpctask_pool;
struct pool     rpcclnt_pool;
#define RPCTASKPOOL_LWM 10
#define RPCTASKPOOL_HWM 40
#else
static          MALLOC_DEFINE(M_RPC, "rpcclnt", "rpc state");
#endif

#define RPC_RETURN(X) do { RPCDEBUG("returning %d", X); return X; }while(0)

/*
 * Estimate rto for an nfs rpc sent via. an unreliable datagram. Use the mean
 * and mean deviation of rtt for the appropriate type of rpc for the frequent
 * rpcs and a default for the others. The justification for doing "other"
 * this way is that these rpcs happen so infrequently that timer est. would
 * probably be stale. Also, since many of these rpcs are non-idempotent, a
 * conservative timeout is desired. getattr, lookup - A+2D read, write     -
 * A+4D other           - nm_timeo
 */
#define	RPC_RTO(n, t) \
	((t) == 0 ? (n)->rc_timeo : \
	 ((t) < 3 ? \
	  (((((n)->rc_srtt[t-1] + 3) >> 2) + (n)->rc_sdrtt[t-1] + 1) >> 1) : \
	  ((((n)->rc_srtt[t-1] + 7) >> 3) + (n)->rc_sdrtt[t-1] + 1)))

#define	RPC_SRTT(s,r)	(r)->r_rpcclnt->rc_srtt[rpcclnt_proct((s),\
				(r)->r_procnum) - 1]

#define	RPC_SDRTT(s,r)	(r)->r_rpcclnt->rc_sdrtt[rpcclnt_proct((s),\
				(r)->r_procnum) - 1]

/*
 * There is a congestion window for outstanding rpcs maintained per mount
 * point. The cwnd size is adjusted in roughly the way that: Van Jacobson,
 * Congestion avoidance and Control, In "Proceedings of SIGCOMM '88". ACM,
 * August 1988. describes for TCP. The cwnd size is chopped in half on a
 * retransmit timeout and incremented by 1/cwnd when each rpc reply is
 * received and a full cwnd of rpcs is in progress. (The sent count and cwnd
 * are scaled for integer arith.) Variants of "slow start" were tried and
 * were found to be too much of a performance hit (ave. rtt 3 times larger),
 * I suspect due to the large rtt that nfs rpcs have.
 */
#define	RPC_CWNDSCALE	256
#define	RPC_MAXCWND	(RPC_CWNDSCALE * 32)
static int      rpcclnt_backoff[8] = {2, 4, 8, 16, 32, 64, 128, 256,};

/* XXX ugly debug strings */
#define RPC_ERRSTR_ACCEPTED_SIZE 6
char *rpc_errstr_accepted[RPC_ERRSTR_ACCEPTED_SIZE] = {
	"",			/* no good message... */
	"remote server hasn't exported program.",
	"remote server can't support version number.",
	"program can't support procedure.",
	"procedure can't decode params.",
	"remote error.  remote side memory allocation failure?"
};

char *rpc_errstr_denied[2] = {
	"remote server doesnt support rpc version 2!",
	"remote server authentication error."
};

#define RPC_ERRSTR_AUTH_SIZE 6
char *rpc_errstr_auth[RPC_ERRSTR_AUTH_SIZE] = {
	"",
	"auth error: bad credential (seal broken).",
	"auth error: client must begin new session.",
	"auth error: bad verifier (seal broken).",
	"auth error: verifier expired or replayed.",
	"auth error: rejected for security reasons.",
};

/*
 * Static data, mostly RPC constants in XDR form
 */
static u_int32_t rpc_reply, rpc_call, rpc_vers;

/*
 * rpc_msgdenied, rpc_mismatch, rpc_auth_unix, rpc_msgaccepted,
 * rpc_autherr, rpc_auth_kerb;
 */

static u_int32_t rpcclnt_xid = 0;
static u_int32_t rpcclnt_xid_touched = 0;
struct rpcstats rpcstats;
int      rpcclnt_ticks;

SYSCTL_NODE(_kern, OID_AUTO, rpc, CTLFLAG_RD, 0, "RPC Subsystem");

SYSCTL_UINT(_kern_rpc, OID_AUTO, retries, CTLFLAG_RD, &rpcstats.rpcretries, 0, "retries");
SYSCTL_UINT(_kern_rpc, OID_AUTO, request, CTLFLAG_RD, &rpcstats.rpcrequests, 0, "request");
SYSCTL_UINT(_kern_rpc, OID_AUTO, timeouts, CTLFLAG_RD, &rpcstats.rpctimeouts, 0, "timeouts");
SYSCTL_UINT(_kern_rpc, OID_AUTO, unexpected, CTLFLAG_RD, &rpcstats.rpcunexpected, 0, "unexpected");
SYSCTL_UINT(_kern_rpc, OID_AUTO, invalid, CTLFLAG_RD, &rpcstats.rpcinvalid, 0, "invalid");

#ifdef RPCCLNT_DEBUG
int             rpcdebugon = 0;
SYSCTL_UINT(_kern_rpc, OID_AUTO, debug_on, CTLFLAG_RW, &rpcdebugon, 0, "RPC Debug messages");
#endif

/*
 * Queue head for rpctask's
 */
static
TAILQ_HEAD(, rpctask) rpctask_q;
struct callout_handle rpcclnt_timer_handle;

#ifdef __OpenBSD__
static int             rpcclnt_send(struct socket *, struct mbuf *, struct mbuf *, struct rpctask *);
static int             rpcclnt_receive(struct rpctask *, struct mbuf **, struct mbuf **, RPC_EXEC_CTX);
#else
static int             rpcclnt_send(struct socket *, struct sockaddr *, struct mbuf *, struct rpctask *);
static int             rpcclnt_receive(struct rpctask *, struct sockaddr **, struct mbuf **, RPC_EXEC_CTX);
#endif

static int             rpcclnt_msg(RPC_EXEC_CTX, const char *, char *);

static int             rpcclnt_reply(struct rpctask *, RPC_EXEC_CTX);
static void            rpcclnt_timer(void *);
static int             rpcclnt_sndlock(int *, struct rpctask *);
static void            rpcclnt_sndunlock(int *);
static int             rpcclnt_rcvlock(struct rpctask *);
static void            rpcclnt_rcvunlock(int *);
#if 0
void            rpcclnt_realign(struct mbuf *, int);
#else
static void	rpcclnt_realign(struct mbuf **, int);
#endif

static struct mbuf    *rpcclnt_buildheader(struct rpcclnt *, int, struct mbuf *, u_int32_t, int *, struct mbuf **, struct ucred *);
static int             rpcm_disct(struct mbuf **, caddr_t *, int, int, caddr_t *);
static u_int32_t       rpcclnt_proct(struct rpcclnt *, u_int32_t);
static int             rpc_adv(struct mbuf **, caddr_t *, int, int);
static void     rpcclnt_softterm(struct rpctask * task);

static int rpcauth_buildheader(struct rpc_auth * auth, struct ucred *, struct mbuf **, caddr_t *);

void
rpcclnt_init(void)
{
#ifdef __OpenBSD__
	static struct timeout rpcclnt_timer_to;
#endif

	rpcclnt_ticks = (hz * RPC_TICKINTVL + 500) / 1000;
	if (rpcclnt_ticks < 1)
		rpcclnt_ticks = 1;
	rpcstats.rpcretries = 0;
	rpcstats.rpcrequests = 0;
	rpcstats.rpctimeouts = 0;
	rpcstats.rpcunexpected = 0;
	rpcstats.rpcinvalid = 0;

	/*
	 * rpc constants how about actually using more than one of these!
	 */

	rpc_reply = txdr_unsigned(RPC_REPLY);
	rpc_vers = txdr_unsigned(RPC_VER2);
	rpc_call = txdr_unsigned(RPC_CALL);
#if 0
	rpc_msgdenied = txdr_unsigned(RPC_MSGDENIED);
	rpc_msgaccepted = txdr_unsigned(RPC_MSGACCEPTED);
	rpc_mismatch = txdr_unsigned(RPC_MISMATCH);
	rpc_autherr = txdr_unsigned(RPC_AUTHERR);
	rpc_auth_unix = txdr_unsigned(RPCAUTH_UNIX);
	rpc_auth_kerb = txdr_unsigned(RPCAUTH_KERB4);
#endif

	/* initialize rpctask queue */
	TAILQ_INIT(&rpctask_q);

#ifdef __OpenBSD__
	/* initialize pools */
	pool_init(&rpctask_pool, sizeof(struct rpctask), 0, 0, RPCTASKPOOL_LWM,
		  "rpctask_p", NULL);
	pool_setlowat(&rpctask_pool, RPCTASKPOOL_LWM);
	pool_sethiwat(&rpctask_pool, RPCTASKPOOL_HWM);

	pool_init(&rpcclnt_pool, sizeof(struct rpcclnt), 0, 0, 1, "rpcclnt_p", NULL);

	/* initialize timers */
	timeout_set(&rpcclnt_timer_to, rpcclnt_timer, &rpcclnt_timer_to);
	rpcclnt_timer(&rpcclnt_timer_to);
#else /* !__OpenBSD__ */
	rpcclnt_timer(NULL);

#endif /* !__OpenBSD__ */

	RPCDEBUG("rpc initialed");

	return;
}

void
rpcclnt_uninit(void)
{
  	RPCDEBUG("uninit");
	untimeout(rpcclnt_timer, (void *)NULL, rpcclnt_timer_handle);

	/* XXX delete sysctl variables? */
}

int
rpcclnt_setup(clnt, program, addr, sotype, soproto, auth, max_read_size, max_write_size, flags)
    struct rpcclnt * clnt;
    struct rpc_program * program;
    struct sockaddr * addr;
    int sotype;
    int soproto;
    struct rpc_auth * auth;
    int max_read_size;
    int max_write_size;
    int flags;
{
	if (clnt == NULL || program == NULL || addr == NULL || auth == NULL)
	  RPC_RETURN (EFAULT);

	if (program->prog_name == NULL)
	  RPC_RETURN (EFAULT);
	clnt->rc_prog = program;

	clnt->rc_name = addr;
	clnt->rc_sotype = sotype;
	clnt->rc_soproto = soproto;
	clnt->rc_auth = auth;
	clnt->rc_rsize = max_read_size;
	clnt->rc_wsize = max_write_size;
	clnt->rc_flag = flags;

	clnt->rc_proctlen = 0;
	clnt->rc_proct = NULL;

	RPC_RETURN (0);
}

/*
 * Initialize sockets and congestion for a new RPC connection. We do not free
 * the sockaddr if error.
 */
int
rpcclnt_connect(rpc, td)
	struct rpcclnt *rpc;
	RPC_EXEC_CTX td;
{
	struct socket  *so;
	int             s, error, rcvreserve, sndreserve;
	struct sockaddr *saddr;

#ifdef __OpenBSD__
	struct sockaddr_in *sin;
	struct mbuf    *m;
#else
	struct sockaddr_in sin;

	int             soarg;
	struct sockopt  opt;
#endif

	if (rpc == NULL) {
		RPCDEBUG("no rpcclnt struct!\n");
		RPC_RETURN(EFAULT);
	}

	GIANT_REQUIRED;		/* XXX until socket locking done */

	/* create the socket */
	rpc->rc_so = NULL;

	saddr = rpc->rc_name;

	error = socreate(saddr->sa_family, &rpc->rc_so, rpc->rc_sotype,
			 rpc->rc_soproto, td->td_ucred, td);

	if (error) {
		RPCDEBUG("error %d in socreate()", error);
		RPC_RETURN(error);
	}
	so = rpc->rc_so;
	rpc->rc_soflags = so->so_proto->pr_flags;

	/*
	 * Some servers require that the client port be a reserved port
	 * number. We always allocate a reserved port, as this prevents
	 * filehandle disclosure through UDP port capture.
	 */
	if (saddr->sa_family == AF_INET) {
#ifdef __OpenBSD__
		struct mbuf    *mopt;
		int            *ip;
#endif

#ifdef __OpenBSD__
		MGET(mopt, M_TRYWAIT, MT_SOOPTS);
		mopt->m_len = sizeof(int);
		ip = mtod(mopt, int *);
		*ip = IP_PORTRANGE_LOW;

		error = sosetopt(so, IPPROTO_IP, IP_PORTRANGE, mopt);
#else
		soarg = IP_PORTRANGE_LOW;
		bzero(&opt, sizeof(struct sockopt));
		opt.sopt_dir = SOPT_SET;
		opt.sopt_level = IPPROTO_IP;
		opt.sopt_name = IP_PORTRANGE;
		opt.sopt_val = &soarg;
		opt.sopt_valsize = sizeof(soarg);

		error = sosetopt(so, &opt);
#endif
		if (error)
			goto bad;

#if __OpenBSD__
		MGET(m, M_TRYWAIT, MT_SONAME);
		sin = mtod(m, struct sockaddr_in *);
		sin->sin_len = m->m_len = sizeof(struct sockaddr_in);
		sin->sin_family = AF_INET;
		sin->sin_addr.s_addr = INADDR_ANY;
		sin->sin_port = htons(0);
		error = sobind(so, m);
		m_freem(m);
#else
		sin.sin_len = sizeof(struct sockaddr_in);
		sin.sin_family = AF_INET;
		sin.sin_addr.s_addr = INADDR_ANY;
		sin.sin_port = htons(0);
		error = sobind(so, (struct sockaddr *) & sin, td);
#endif
		if (error)
			goto bad;

#if __OpenBSD__
		MGET(mopt, M_TRYWAIT, MT_SOOPTS);
		mopt->m_len = sizeof(int);
		ip = mtod(mopt, int *);
		*ip = IP_PORTRANGE_DEFAULT;
		error = sosetopt(so, IPPROTO_IP, IP_PORTRANGE, mopt);
#else
		soarg = IP_PORTRANGE_DEFAULT;
		bzero(&opt, sizeof(struct sockopt));
		opt.sopt_dir = SOPT_SET;
		opt.sopt_level = IPPROTO_IP;
		opt.sopt_name = IP_PORTRANGE;
		opt.sopt_val = &soarg;
		opt.sopt_valsize = sizeof(soarg);
		error = sosetopt(so, &opt);
#endif
		if (error)
			goto bad;
	}
	/*
	 * Protocols that do not require connections may be optionally left
	 * unconnected for servers that reply from a port other than
	 * NFS_PORT.
	 */
	if (rpc->rc_flag & RPCCLNT_NOCONN) {
		if (rpc->rc_soflags & PR_CONNREQUIRED) {
			error = ENOTCONN;
			goto bad;
		}
	} else {
		error = soconnect(so, saddr, td);
		if (error)
			goto bad;

		/*
		 * Wait for the connection to complete. Cribbed from the
		 * connect system call but with the wait timing out so that
		 * interruptible mounts don't hang here for a long time.
		 */
#ifdef __OpenBSD__
		s = splsoftnet();
#else
		s = splnet();
#endif
		while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
			(void)tsleep((caddr_t) & so->so_timeo, PSOCK,
				     "rpc", 2 * hz);

			/*
			 * XXX needs to catch interrupt signals. something
			 * like this: if ((so->so_state & SS_ISCONNECTING) &&
			 * so->so_error == 0 && rep && (error =
			 * nfs_sigintr(nmp, rep, rep->r_td)) != 0) {
			 * so->so_state &= ~SS_ISCONNECTING; splx(s); goto
			 * bad; }
			 */
		}
		if (so->so_error) {
			error = so->so_error;
			so->so_error = 0;
			splx(s);
			goto bad;
		}
		splx(s);
	}
	if (rpc->rc_flag & (RPCCLNT_SOFT | RPCCLNT_INT)) {
		so->so_rcv.sb_timeo = (5 * hz);
		so->so_snd.sb_timeo = (5 * hz);
	} else {
		so->so_rcv.sb_timeo = 0;
		so->so_snd.sb_timeo = 0;
	}

	if (rpc->rc_sotype == SOCK_DGRAM) {
		sndreserve = rpc->rc_wsize + RPC_MAXPKTHDR;
		rcvreserve = rpc->rc_rsize + RPC_MAXPKTHDR;
	} else if (rpc->rc_sotype == SOCK_SEQPACKET) {
		sndreserve = (rpc->rc_wsize + RPC_MAXPKTHDR) * 2;
		rcvreserve = (rpc->rc_rsize + RPC_MAXPKTHDR) * 2;
	} else {
		if (rpc->rc_sotype != SOCK_STREAM)
			panic("rpcclnt_connect() bad sotype");
		if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
#ifdef __OpenBSD__
			MGET(m, M_TRYWAIT, MT_SOOPTS);
			*mtod(m, int32_t *) = 1;
			m->m_len = sizeof(int32_t);
			sosetopt(so, SOL_SOCKET, SO_KEEPALIVE, m);
#else
			soarg = 1;

			bzero(&opt, sizeof(struct sockopt));
			opt.sopt_dir = SOPT_SET;
			opt.sopt_level = SOL_SOCKET;
			opt.sopt_name = SO_KEEPALIVE;
			opt.sopt_val = &soarg;
			opt.sopt_valsize = sizeof(soarg);
			sosetopt(so, &opt);
#endif
		}
		if (so->so_proto->pr_protocol == IPPROTO_TCP) {
#ifdef __OpenBSD__
			MGET(m, M_TRYWAIT, MT_SOOPTS);
			*mtod(m, int32_t *) = 1;
			m->m_len = sizeof(int32_t);
			sosetopt(so, IPPROTO_TCP, TCP_NODELAY, m);
#else
			soarg = 1;

			bzero(&opt, sizeof(struct sockopt));
			opt.sopt_dir = SOPT_SET;
			opt.sopt_level = IPPROTO_TCP;
			opt.sopt_name = TCP_NODELAY;
			opt.sopt_val = &soarg;
			opt.sopt_valsize = sizeof(soarg);
			sosetopt(so, &opt);
#endif
		}
		sndreserve = (rpc->rc_wsize + RPC_MAXPKTHDR +
			      sizeof(u_int32_t)) * 2;
		rcvreserve = (rpc->rc_rsize + RPC_MAXPKTHDR +
			      sizeof(u_int32_t)) * 2;
	}
	error = soreserve(so, sndreserve, rcvreserve);
	if (error)
		goto bad;
	so->so_rcv.sb_flags |= SB_NOINTR;
	so->so_snd.sb_flags |= SB_NOINTR;

	/* Initialize other non-zero congestion variables */
	rpc->rc_srtt[0] = rpc->rc_srtt[1] = rpc->rc_srtt[2] = rpc->rc_srtt[3] =
		rpc->rc_srtt[4] = (RPC_TIMEO << 3);
	rpc->rc_sdrtt[0] = rpc->rc_sdrtt[1] = rpc->rc_sdrtt[2] =
		rpc->rc_sdrtt[3] = rpc->rc_sdrtt[4] = 0;
	rpc->rc_cwnd = RPC_MAXCWND / 2;	/* Initial send window */
	rpc->rc_sent = 0;
	rpc->rc_timeouts = 0;
	RPC_RETURN(0);

bad:
	rpcclnt_disconnect(rpc);
	RPC_RETURN(error);
}

/*
 * Reconnect routine: Called when a connection is broken on a reliable
 * protocol. - clean up the old socket - nfs_connect() again - set
 * R_MUSTRESEND for all outstanding requests on mount point If this fails the
 * mount point is DEAD! nb: Must be called with the nfs_sndlock() set on the
 * mount point.
 */
int
rpcclnt_reconnect(rep, td)
	struct rpctask *rep;
	RPC_EXEC_CTX td;
{
	struct rpctask *rp;
	struct rpcclnt *rpc = rep->r_rpcclnt;
	int             error;

	rpcclnt_disconnect(rpc);
	while ((error = rpcclnt_connect(rpc, td)) != 0) {
		if (error == EINTR || error == ERESTART)
			RPC_RETURN(EINTR);
		tsleep(&lbolt, PSOCK, "rpccon", 0);
	}

	/*
	 * Loop through outstanding request list and fix up all requests on
	 * old socket.
	 */
	for (rp = TAILQ_FIRST(&rpctask_q); rp != NULL;
	     rp = TAILQ_NEXT(rp, r_chain)) {
		if (rp->r_rpcclnt == rpc)
			rp->r_flags |= R_MUSTRESEND;
	}
	RPC_RETURN(0);
}

/*
 * NFS disconnect. Clean up and unlink.
 */
void
rpcclnt_disconnect(rpc)
	struct rpcclnt *rpc;
{
	struct socket  *so;

	GIANT_REQUIRED;		/* XXX until socket locking done */

	if (rpc->rc_so) {
		so = rpc->rc_so;
		rpc->rc_so = NULL;
		soshutdown(so, 2);
		soclose(so);
	}
}

void
rpcclnt_safedisconnect(struct rpcclnt * rpc)
{
	struct rpctask  dummytask;

	bzero(&dummytask, sizeof(dummytask));
	dummytask.r_rpcclnt = rpc;
	rpcclnt_rcvlock(&dummytask);
	rpcclnt_disconnect(rpc);
	rpcclnt_rcvunlock(&rpc->rc_flag);
}

/*
 * This is the nfs send routine. For connection based socket types, it must
 * be called with an nfs_sndlock() on the socket. "rep == NULL" indicates
 * that it has been called from a server. For the client side: - return EINTR
 * if the RPC is terminated, 0 otherwise - set R_MUSTRESEND if the send fails
 * for any reason - do any cleanup required by recoverable socket errors
 * (???) For the server side: - return EINTR or ERESTART if interrupted by a
 * signal - return EPIPE if a connection is lost for connection based sockets
 * (TCP...) - do any cleanup required by recoverable socket errors (???)
 */
static int
rpcclnt_send(so, nam, top, rep)
	struct socket  *so;
#ifdef __OpenBSD__
	struct mbuf    *nam;
#else
	struct sockaddr *nam;
#endif
	struct mbuf    *top;
	struct rpctask *rep;
{
#ifdef __OpenBSD__
	struct mbuf    *sendnam;
#else
	struct sockaddr *sendnam;
	struct thread  *td = curthread;
#endif
	int error, soflags, flags;

	GIANT_REQUIRED;		/* XXX until socket locking done */

	if (rep) {
		if (rep->r_flags & R_SOFTTERM) {
			m_freem(top);
			RPC_RETURN(EINTR);
		}
		if ((so = rep->r_rpcclnt->rc_so) == NULL) {
			rep->r_flags |= R_MUSTRESEND;
			m_freem(top);
			RPC_RETURN(0);
		}
		rep->r_flags &= ~R_MUSTRESEND;
		soflags = rep->r_rpcclnt->rc_soflags;
	} else
		soflags = so->so_proto->pr_flags;

	if ((soflags & PR_CONNREQUIRED) || (so->so_state & SS_ISCONNECTED))
		sendnam = NULL;
	else
		sendnam = nam;

	if (so->so_type == SOCK_SEQPACKET)
		flags = MSG_EOR;
	else
		flags = 0;

	error = sosend(so, sendnam, NULL, top, NULL, flags, td);

	if (error) {
		if (rep) {
			log(LOG_INFO, "rpc send error %d for service %s\n", error,
			    rep->r_rpcclnt->rc_prog->prog_name);
			/*
			 * Deal with errors for the client side.
			 */
			if (rep->r_flags & R_SOFTTERM)
				error = EINTR;
			else
				rep->r_flags |= R_MUSTRESEND;
		} else
			log(LOG_INFO, "rpc service send error %d\n", error);

		/*
		 * Handle any recoverable (soft) socket errors here.
		 */
		if (error != EINTR && error != ERESTART &&
		    error != EWOULDBLOCK && error != EPIPE)
			error = 0;
	}
	RPC_RETURN(error);
}

/*
 * Receive a Sun RPC Request/Reply. For SOCK_DGRAM, the work is all done by
 * soreceive(), but for SOCK_STREAM we must deal with the Record Mark and
 * consolidate the data into a new mbuf list. nb: Sometimes TCP passes the
 * data up to soreceive() in long lists of small mbufs. For SOCK_STREAM we
 * must be very careful to read an entire record once we have read any of it,
 * even if the system call has been interrupted.
 */
static int
rpcclnt_receive(rep, aname, mp, td)
	struct rpctask *rep;
#ifdef __OpenBSD__
	struct mbuf   **aname;
#else
	struct sockaddr **aname;
#endif
	struct mbuf   **mp;
	RPC_EXEC_CTX  td;
{
	struct socket  *so;
	struct uio      auio;
	struct iovec    aio;
	struct mbuf    *m;
	struct mbuf    *control;
	u_int32_t       len;
#ifdef __OpenBSD__
	struct mbuf   **getnam;
#else
	struct sockaddr **getnam;
#endif
	int error, sotype, rcvflg;

	GIANT_REQUIRED;		/* XXX until socket locking done */

	/*
	 * Set up arguments for soreceive()
	 */
	*mp = NULL;
	*aname = NULL;
	sotype = rep->r_rpcclnt->rc_sotype;

	/*
	 * For reliable protocols, lock against other senders/receivers in
	 * case a reconnect is necessary. For SOCK_STREAM, first get the
	 * Record Mark to find out how much more there is to get. We must
	 * lock the socket against other receivers until we have an entire
	 * rpc request/reply.
	 */
	if (sotype != SOCK_DGRAM) {
		error = rpcclnt_sndlock(&rep->r_rpcclnt->rc_flag, rep);
		if (error)
			RPC_RETURN(error);
tryagain:
		/*
		 * Check for fatal errors and resending request.
		 */
		/*
		 * Ugh: If a reconnect attempt just happened, rc_so would
		 * have changed. NULL indicates a failed attempt that has
		 * essentially shut down this mount point.
		 */
		if (rep->r_mrep || (rep->r_flags & R_SOFTTERM)) {
			rpcclnt_sndunlock(&rep->r_rpcclnt->rc_flag);
			RPC_RETURN(EINTR);
		}
		so = rep->r_rpcclnt->rc_so;
		if (!so) {
			error = rpcclnt_reconnect(rep, td);
			if (error) {
				rpcclnt_sndunlock(&rep->r_rpcclnt->rc_flag);
				RPC_RETURN(error);
			}
			goto tryagain;
		}
		while (rep->r_flags & R_MUSTRESEND) {
			m = m_copym(rep->r_mreq, 0, M_COPYALL, M_TRYWAIT);
			rpcstats.rpcretries++;
			error = rpcclnt_send(so, rep->r_rpcclnt->rc_name, m, rep);
			if (error) {
				if (error == EINTR || error == ERESTART ||
				    (error = rpcclnt_reconnect(rep, td)) != 0) {
					rpcclnt_sndunlock(&rep->r_rpcclnt->rc_flag);
					RPC_RETURN(error);
				}
				goto tryagain;
			}
		}
		rpcclnt_sndunlock(&rep->r_rpcclnt->rc_flag);
		if (sotype == SOCK_STREAM) {
			aio.iov_base = (caddr_t) & len;
			aio.iov_len = sizeof(u_int32_t);
			auio.uio_iov = &aio;
			auio.uio_iovcnt = 1;
			auio.uio_segflg = UIO_SYSSPACE;
			auio.uio_rw = UIO_READ;
			auio.uio_offset = 0;
			auio.uio_resid = sizeof(u_int32_t);
#ifdef __OpenBSD__
			auio.uio_procp = td;
#else
			auio.uio_td = td;
#endif
			do {
				rcvflg = MSG_WAITALL;
				error = soreceive(so, NULL, &auio, NULL, NULL, &rcvflg);
				if (error == EWOULDBLOCK && rep) {
					if (rep->r_flags & R_SOFTTERM)
						RPC_RETURN(EINTR);
				}
			} while (error == EWOULDBLOCK);
			if (!error && auio.uio_resid > 0) {
				log(LOG_INFO,
				"short receive (%zu/%zu) from rpc server %s\n",
				    sizeof(u_int32_t) - auio.uio_resid,
				    sizeof(u_int32_t),
				    rep->r_rpcclnt->rc_prog->prog_name);
				error = EPIPE;
			}
			if (error)
				goto errout;
			len = ntohl(len) & ~0x80000000;
			/*
			 * This is SERIOUS! We are out of sync with the
			 * sender and forcing a disconnect/reconnect is all I
			 * can do.
			 */
			if (len > RPC_MAXPACKET) {
				log(LOG_ERR, "%s (%d) from rpc server %s\n",
				    "impossible packet length",
				    len,
				    rep->r_rpcclnt->rc_prog->prog_name);
				error = EFBIG;
				goto errout;
			}
			auio.uio_resid = len;
			do {
				rcvflg = MSG_WAITALL;
				error = soreceive(so, NULL, &auio, mp, NULL, &rcvflg);
			} while (error == EWOULDBLOCK || error == EINTR ||
				 error == ERESTART);
			if (!error && auio.uio_resid > 0) {
				log(LOG_INFO,
				"short receive (%d/%d) from rpc server %s\n",
				    len - auio.uio_resid, len,
				    rep->r_rpcclnt->rc_prog->prog_name);
				error = EPIPE;
			}
		} else {
			/*
			 * NB: Since uio_resid is big, MSG_WAITALL is ignored
			 * and soreceive() will return when it has either a
			 * control msg or a data msg. We have no use for
			 * control msg., but must grab them and then throw
			 * them away so we know what is going on.
			 */
			auio.uio_resid = len = 100000000;	/* Anything Big */
#ifdef __OpenBSD__
			auio.uio_procp = td;
#else
			auio.uio_td = td;
#endif
			do {
				rcvflg = 0;
				error = soreceive(so, NULL, &auio, mp, &control, &rcvflg);
				if (control)
					m_freem(control);
				if (error == EWOULDBLOCK && rep) {
					if (rep->r_flags & R_SOFTTERM)
						RPC_RETURN(EINTR);
				}
			} while (error == EWOULDBLOCK ||
				 (!error && *mp == NULL && control));
			if ((rcvflg & MSG_EOR) == 0)
				printf("Egad!!\n");
			if (!error && *mp == NULL)
				error = EPIPE;
			len -= auio.uio_resid;
		}
errout:
		if (error && error != EINTR && error != ERESTART) {
			m_freem(*mp);
			*mp = (struct mbuf *) 0;
			if (error != EPIPE)
				log(LOG_INFO,
				    "receive error %d from rpc server %s\n",
				    error,
				    rep->r_rpcclnt->rc_prog->prog_name);
			error = rpcclnt_sndlock(&rep->r_rpcclnt->rc_flag, rep);
			if (!error)
				error = rpcclnt_reconnect(rep, td);
			if (!error)
				goto tryagain;
		}
	} else {
		if ((so = rep->r_rpcclnt->rc_so) == NULL)
			RPC_RETURN(EACCES);
		if (so->so_state & SS_ISCONNECTED)
			getnam = NULL;
		else
			getnam = aname;
		auio.uio_resid = len = 1000000;
#ifdef __OpenBSD__
		auio.uio_procp = td;
#else
		auio.uio_td = td;
#endif

		do {
			rcvflg = 0;
			error = soreceive(so, getnam, &auio, mp, NULL, &rcvflg);
			RPCDEBUG("soreceivce returns %d", error);
			if (error == EWOULDBLOCK && (rep->r_flags & R_SOFTTERM)) {
				RPCDEBUG("wouldblock && softerm -> EINTR");
				RPC_RETURN(EINTR);
			}
		} while (error == EWOULDBLOCK);
		len -= auio.uio_resid;
	}
	if (error) {
		m_freem(*mp);
		*mp = NULL;
	}

	/*
	 * Search for any mbufs that are not a multiple of 4 bytes
	 * long or with m_data not longword aligned. These could
	 * cause pointer alignment problems, so copy them to well
	 * aligned mbufs.
	 */
	rpcclnt_realign(mp, 5 * RPCX_UNSIGNED);
	RPC_RETURN(error);
}

/*
 * Implement receipt of reply on a socket. We must search through the list of
 * received datagrams matching them with outstanding requests using the xid,
 * until ours is found.
 */
/* ARGSUSED */
static int
rpcclnt_reply(myrep, td)
	struct rpctask *myrep;
	RPC_EXEC_CTX td;
{
	struct rpctask *rep;
	struct rpcclnt *rpc = myrep->r_rpcclnt;
	int32_t         t1;
	struct mbuf    *mrep, *md;
#ifdef __OpenBSD__
	struct mbuf    *nam;
#else
	struct sockaddr *nam;
#endif
	u_int32_t       rxid, *tl;
	caddr_t         dpos, cp2;
	int             error;

	/*
	 * Loop around until we get our own reply
	 */
	for (;;) {
		/*
		 * Lock against other receivers so that I don't get stuck in
		 * sbwait() after someone else has received my reply for me.
		 * Also necessary for connection based protocols to avoid
		 * race conditions during a reconnect.
		 */
		error = rpcclnt_rcvlock(myrep);
		if (error)
			RPC_RETURN(error);
		/* Already received, bye bye */
		if (myrep->r_mrep != NULL) {
			rpcclnt_rcvunlock(&rpc->rc_flag);
			RPC_RETURN(0);
		}
		/*
		 * Get the next Rpc reply off the socket
		 */
		error = rpcclnt_receive(myrep, &nam, &mrep, td);

		rpcclnt_rcvunlock(&rpc->rc_flag);

		if (error) {
			/*
			 * Ignore routing errors on connectionless
			 * protocols??
			 */
			if (RPCIGNORE_SOERROR(rpc->rc_soflags, error)) {
				rpc->rc_so->so_error = 0;
				if (myrep->r_flags & R_GETONEREP)
					RPC_RETURN(0);
				RPCDEBUG("ingoring routing error on connectionless protocol.");
				continue;
			}
			RPC_RETURN(error);
		}
#ifdef __OpenBSD__
		if (nam)
			m_freem(nam);
#else
		if (nam)
			FREE(nam, M_SONAME);
#endif

		/*
		 * Get the xid and check that it is an rpc reply
		 */
		md = mrep;
		dpos = mtod(md, caddr_t);
		rpcm_dissect(tl, u_int32_t *, 2 * RPCX_UNSIGNED);
		rxid = *tl++;
		if (*tl != rpc_reply) {
			rpcstats.rpcinvalid++;
			m_freem(mrep);
rpcmout:
			if (myrep->r_flags & R_GETONEREP)
				RPC_RETURN(0);
			continue;
		}
		/*
		 * Loop through the request list to match up the reply Iff no
		 * match, just drop the datagram
		 */
		TAILQ_FOREACH(rep, &rpctask_q, r_chain) {
			if (rep->r_mrep == NULL && rxid == rep->r_xid) {
				/* Found it.. */
				rep->r_mrep = mrep;
				rep->r_md = md;
				rep->r_dpos = dpos;

				/*
				 * Update congestion window. Do the additive
				 * increase of one rpc/rtt.
				 */
				if (rpc->rc_cwnd <= rpc->rc_sent) {
					rpc->rc_cwnd +=
						(RPC_CWNDSCALE * RPC_CWNDSCALE +
					(rpc->rc_cwnd >> 1)) / rpc->rc_cwnd;
					if (rpc->rc_cwnd > RPC_MAXCWND)
						rpc->rc_cwnd = RPC_MAXCWND;
				}
				rep->r_flags &= ~R_SENT;
				rpc->rc_sent -= RPC_CWNDSCALE;
				/*
				 * Update rtt using a gain of 0.125 on the
				 * mean and a gain of 0.25 on the deviation.
				 */
				if (rep->r_flags & R_TIMING) {
					/*
					 * Since the timer resolution of
					 * NFS_HZ is so course, it can often
					 * result in r_rtt == 0. Since r_rtt
					 * == N means that the actual rtt is
					 * between N+dt and N+2-dt ticks, add
					 * 1.
					 */
					t1 = rep->r_rtt + 1;
					t1 -= (RPC_SRTT(rpc, rep) >> 3);
					RPC_SRTT(rpc, rep) += t1;
					if (t1 < 0)
						t1 = -t1;
					t1 -= (RPC_SDRTT(rpc, rep) >> 2);
					RPC_SDRTT(rpc, rep) += t1;
				}
				rpc->rc_timeouts = 0;
				break;
			}
		}
		/*
		 * If not matched to a request, drop it. If it's mine, get
		 * out.
		 */
		if (rep == 0) {
			rpcstats.rpcunexpected++;
			RPCDEBUG("rpc reply not matched\n");
			m_freem(mrep);
		} else if (rep == myrep) {
			if (rep->r_mrep == NULL)
				panic("rpcreply nil");
			RPC_RETURN(0);
		}
		if (myrep->r_flags & R_GETONEREP)
			RPC_RETURN(0);
	}
}

/* XXX: ignores tryagain! */
/*
 * code from nfs_request - goes something like this - fill in task struct -
 * links task into list - calls nfs_send() for first transmit - calls
 * nfs_receive() to get reply - fills in reply (which should be initialized
 * prior to calling), which is valid when 0 is returned and is NEVER freed in
 * this function
 *
 * always frees the request header, but NEVER frees 'mrest'
 *
 */
/*
 * ruthtype
 * pcclnt_setauth() should be used before calling this. EAUTH is returned if
 * authentication fails.
 */
/*
 * note that reply->result_* are invalid unless reply->type ==
 * RPC_MSGACCEPTED and reply->status == RPC_SUCCESS and that reply->verf_*
 * are invalid unless reply->type == RPC_MSGACCEPTED
 */
int
rpcclnt_request(rpc, mrest, procnum, td, cred, reply)
	struct rpcclnt *rpc;
	struct mbuf    *mrest;
	int             procnum;
	RPC_EXEC_CTX	td;
	struct ucred   *cred;
	struct rpc_reply *reply;
{
	struct mbuf    *m, *mrep;
	struct rpctask *task;
	u_int32_t      *tl;
	struct mbuf    *md, *mheadend;
	caddr_t         dpos, cp2;
	int             t1, s, error = 0, mrest_len;
	u_int32_t       xid;

#ifdef __OpenBSD__
	task = pool_get(&rpctask_pool, PR_WAITOK);
#else
	MALLOC(task, struct rpctask *, sizeof(struct rpctask), M_RPC, (M_WAITOK | M_ZERO));
#endif

	task->r_rpcclnt = rpc;
	task->r_procnum = procnum;
	task->r_td = td;

	mrest_len = m_length(mrest, NULL);

	m = rpcclnt_buildheader(rpc, procnum, mrest, mrest_len, &xid, &mheadend,
	    cred);

	/*
	 * For stream protocols, insert a Sun RPC Record Mark.
	 */
	if (rpc->rc_sotype == SOCK_STREAM) {
		M_PREPEND(m, RPCX_UNSIGNED, M_TRYWAIT);
		*mtod(m, u_int32_t *) = htonl(0x80000000 |
					 (m->m_pkthdr.len - RPCX_UNSIGNED));
	}
	task->r_mreq = m;
	task->r_xid = xid;

	if (rpc->rc_flag & RPCCLNT_SOFT)
		task->r_retry = rpc->rc_retry;
	else
		task->r_retry = RPC_MAXREXMIT + 1;	/* past clip limit */
	task->r_rtt = task->r_rexmit = 0;

	if (rpcclnt_proct(rpc, procnum) > 0)
		task->r_flags = R_TIMING;
	else
		task->r_flags = 0;
	task->r_mrep = NULL;

	/*
	 * Do the client side RPC.
	 */
	rpcstats.rpcrequests++;

	/*
	 * Chain request into list of outstanding requests. Be sure to put it
	 * LAST so timer finds oldest requests first.
	 */
	s = splsoftclock();
	TAILQ_INSERT_TAIL(&rpctask_q, task, r_chain);

	/*
	 * If backing off another request or avoiding congestion, don't send
	 * this one now but let timer do it. If not timing a request, do it
	 * now.
	 */
	if (rpc->rc_so && (rpc->rc_sotype != SOCK_DGRAM ||
			   (rpc->rc_flag & RPCCLNT_DUMBTIMR) ||
			   rpc->rc_sent < rpc->rc_cwnd)) {
		splx(s);

		if (rpc->rc_soflags & PR_CONNREQUIRED)
			error = rpcclnt_sndlock(&rpc->rc_flag, task);
		if (!error) {
			error = rpcclnt_send(rpc->rc_so, rpc->rc_name,
					     m_copym(m, 0, M_COPYALL, M_TRYWAIT),
					     task);
			if (rpc->rc_soflags & PR_CONNREQUIRED)
				rpcclnt_sndunlock(&rpc->rc_flag);
		}
		if (!error && (task->r_flags & R_MUSTRESEND) == 0) {
			rpc->rc_sent += RPC_CWNDSCALE;
			task->r_flags |= R_SENT;
		}
	} else {
		splx(s);
		task->r_rtt = -1;
	}

	/*
	 * Wait for the reply from our send or the timer's.
	 */
	if (!error || error == EPIPE)
		error = rpcclnt_reply(task, td);

	/*
	 * RPC done, unlink the request.
	 */
	s = splsoftclock();
	TAILQ_REMOVE(&rpctask_q, task, r_chain);
	splx(s);

	/*
	 * Decrement the outstanding request count.
	 */
	if (task->r_flags & R_SENT) {
		task->r_flags &= ~R_SENT;	/* paranoia */
		rpc->rc_sent -= RPC_CWNDSCALE;
	}
	/*
	 * If there was a successful reply and a tprintf msg. tprintf a
	 * response.
	 */
	if (!error && (task->r_flags & R_TPRINTFMSG))
		rpcclnt_msg(task->r_td, rpc->rc_prog->prog_name,
			    "is alive again");

	/* free request header (leaving mrest) */
	mheadend->m_next = NULL;
	m_freem(task->r_mreq);

	/* initialize reply */
	reply->mrep = task->r_mrep;
	reply->verf_md = NULL;
	reply->result_md = NULL;

	mrep = task->r_mrep;
	md = task->r_md;
	dpos = task->r_dpos;

	/* task structure is no longer needed */
#ifdef __OpenBSD__
	pool_put(&rpctask_pool, task);
#else
	FREE(task, M_RPC);
#endif

	if (error)
		goto rpcmout;

	/*
	 * break down the rpc header and check if ok
	 */

	rpcm_dissect(tl, u_int32_t *, RPCX_UNSIGNED);
	reply->stat.type = fxdr_unsigned(u_int32_t, *tl);

	if (reply->stat.type == RPC_MSGDENIED) {
		rpcm_dissect(tl, u_int32_t *, RPCX_UNSIGNED);
		reply->stat.status = fxdr_unsigned(u_int32_t, *tl);

		switch (reply->stat.status) {
		case RPC_MISMATCH:
			rpcm_dissect(tl, u_int32_t *, 2 * RPCX_UNSIGNED);
			reply->stat.mismatch_info.low = fxdr_unsigned(u_int32_t, *tl++);
			reply->stat.mismatch_info.high = fxdr_unsigned(u_int32_t, *tl);
			error = EOPNOTSUPP;
			break;
		case RPC_AUTHERR:
			rpcm_dissect(tl, u_int32_t *, RPCX_UNSIGNED);
			reply->stat.autherr = fxdr_unsigned(u_int32_t, *tl);
			error = EACCES;
			break;
		default:
			error = EBADRPC;
			break;
		}
		goto rpcmout;
	} else if (reply->stat.type != RPC_MSGACCEPTED) {
		error = EBADRPC;
  		goto rpcmout;
  	}

	rpcm_dissect(tl, u_int32_t *, 2 * RPCX_UNSIGNED);

	reply->verf_md = md;
	reply->verf_dpos = dpos;

	reply->verf_type = fxdr_unsigned(u_int32_t, *tl++);
	reply->verf_size = fxdr_unsigned(u_int32_t, *tl);

	if (reply->verf_size != 0)
		rpcm_adv(rpcm_rndup(reply->verf_size));

	rpcm_dissect(tl, u_int32_t *, RPCX_UNSIGNED);
	reply->stat.status = fxdr_unsigned(u_int32_t, *tl);

	if (reply->stat.status == RPC_SUCCESS) {
		if ((uint32_t)(dpos - mtod(md, caddr_t)) >= md->m_len) {
			RPCDEBUG("where is the next mbuf?");
			RPCDEBUG("%d -> %d",
			    (int)(dpos - mtod(md, caddr_t)), md->m_len);
			if (md->m_next == NULL) {
				error = EBADRPC;
				goto rpcmout;
			} else {
				reply->result_md = md->m_next;
				reply->result_dpos = mtod(reply->result_md,
				    caddr_t);
			}
		} else {
			reply->result_md = md;
			reply->result_dpos = dpos;
		}
	} else if (reply->stat.status == RPC_PROGMISMATCH) {
		rpcm_dissect(tl, u_int32_t *, 2 * RPCX_UNSIGNED);
		reply->stat.mismatch_info.low = fxdr_unsigned(u_int32_t, *tl++);
		reply->stat.mismatch_info.high = fxdr_unsigned(u_int32_t, *tl);
		error = EOPNOTSUPP;
		goto rpcmout;
	} else {
		error = EPROTONOSUPPORT;
		goto rpcmout;
	}
	error = 0;

rpcmout:
	RPC_RETURN(error);
}

/*
 * Nfs timer routine Scan the nfsreq list and retranmit any requests that
 * have timed out To avoid retransmission attempts on STREAM sockets (in the
 * future) make sure to set the r_retry field to 0 (implies nm_retry == 0).
 */
void
rpcclnt_timer(arg)
	void           *arg;
{
#ifdef __OpenBSD__
	struct timeout *to = (struct timeout *) arg;
#endif
	struct rpctask *rep;
	struct mbuf    *m;
	struct socket  *so;
	struct rpcclnt *rpc;
	int             timeo;
	int             s, error;

#ifndef __OpenBSD__
	struct thread  *td = curthread;
#endif

#if __OpenBSD__
	s = splsoftnet();
#else
	s = splnet();
#endif
	TAILQ_FOREACH(rep, &rpctask_q, r_chain) {
		rpc = rep->r_rpcclnt;
		if (rep->r_mrep || (rep->r_flags & R_SOFTTERM))
			continue;
		if (rpcclnt_sigintr(rpc, rep, rep->r_td)) {
			rep->r_flags |= R_SOFTTERM;
			continue;
		}
		if (rep->r_rtt >= 0) {
			rep->r_rtt++;
			if (rpc->rc_flag & RPCCLNT_DUMBTIMR)
				timeo = rpc->rc_timeo;
			else
				timeo = RPC_RTO(rpc, rpcclnt_proct(rep->r_rpcclnt,
							   rep->r_procnum));
			if (rpc->rc_timeouts > 0)
				timeo *= rpcclnt_backoff[rpc->rc_timeouts - 1];
			if (rep->r_rtt <= timeo)
				continue;
			if (rpc->rc_timeouts < 8)
				rpc->rc_timeouts++;
		}
		/*
		 * Check for server not responding
		 */
		if ((rep->r_flags & R_TPRINTFMSG) == 0 &&
		    rep->r_rexmit > rpc->rc_deadthresh) {
			rpcclnt_msg(rep->r_td, rpc->rc_prog->prog_name,
				    "not responding");
			rep->r_flags |= R_TPRINTFMSG;
		}
		if (rep->r_rexmit >= rep->r_retry) {	/* too many */
			rpcstats.rpctimeouts++;
			rep->r_flags |= R_SOFTTERM;
			continue;
		}
		if (rpc->rc_sotype != SOCK_DGRAM) {
			if (++rep->r_rexmit > RPC_MAXREXMIT)
				rep->r_rexmit = RPC_MAXREXMIT;
			continue;
		}
		if ((so = rpc->rc_so) == NULL)
			continue;

		/*
		 * If there is enough space and the window allows.. Resend it
		 * Set r_rtt to -1 in case we fail to send it now.
		 */
		rep->r_rtt = -1;
		if (sbspace(&so->so_snd) >= rep->r_mreq->m_pkthdr.len &&
		    ((rpc->rc_flag & RPCCLNT_DUMBTIMR) ||
		     (rep->r_flags & R_SENT) ||
		     rpc->rc_sent < rpc->rc_cwnd) &&
		    (m = m_copym(rep->r_mreq, 0, M_COPYALL, M_DONTWAIT))) {
			if ((rpc->rc_flag & RPCCLNT_NOCONN) == 0)
				error = (*so->so_proto->pr_usrreqs->pru_send) (so, 0, m,
							    NULL, NULL, td);
			else
				error = (*so->so_proto->pr_usrreqs->pru_send)(so, 0, m, rpc->rc_name, NULL, td);
			if (error) {
				if (RPCIGNORE_SOERROR(rpc->rc_soflags, error))
					so->so_error = 0;
			} else {
				/*
				 * Iff first send, start timing else turn
				 * timing off, backoff timer and divide
				 * congestion window by 2.
				 */
				if (rep->r_flags & R_SENT) {
					rep->r_flags &= ~R_TIMING;
					if (++rep->r_rexmit > RPC_MAXREXMIT)
						rep->r_rexmit = RPC_MAXREXMIT;
					rpc->rc_cwnd >>= 1;
					if (rpc->rc_cwnd < RPC_CWNDSCALE)
						rpc->rc_cwnd = RPC_CWNDSCALE;
					rpcstats.rpcretries++;
				} else {
					rep->r_flags |= R_SENT;
					rpc->rc_sent += RPC_CWNDSCALE;
				}
				rep->r_rtt = 0;
			}
		}
	}
	splx(s);

#ifdef __OpenBSD__
	timeout_add(rpcclnt_timer, to, rpcclnt_ticks);
#else
	rpcclnt_timer_handle = timeout(rpcclnt_timer, NULL, rpcclnt_ticks);
#endif
}

/*
 * Test for a termination condition pending on the process. This is used for
 * RPCCLNT_INT mounts.
 */
int
rpcclnt_sigintr(rpc, task, pr)
	struct rpcclnt *rpc;
	struct rpctask *task;
	RPC_EXEC_CTX pr;
{
	struct proc    *p;

	sigset_t        tmpset;

	if (rpc == NULL)
		return EFAULT;

	/* XXX deal with forced unmounts */

	if (task && (task->r_flags & R_SOFTTERM))
		RPC_RETURN(EINTR);

	if (!(rpc->rc_flag & RPCCLNT_INT))
		RPC_RETURN(0);

	if (pr == NULL)
		return (0);

#ifdef __OpenBSD__
	p = pr;
	if (p && p->p_siglist &&
	    (((p->p_siglist & ~p->p_sigmask) & ~p->p_sigignore) &
	     RPCINT_SIGMASK))
		RPC_RETURN(EINTR);
#else
	p = pr->td_proc;
	PROC_LOCK(p);
	tmpset = p->p_siglist;
	SIGSETNAND(tmpset, pr->td_sigmask);
	mtx_lock(&p->p_sigacts->ps_mtx);
	SIGSETNAND(tmpset, p->p_sigacts->ps_sigignore);
	mtx_unlock(&p->p_sigacts->ps_mtx);
	if (SIGNOTEMPTY(p->p_siglist) && RPCCLNTINT_SIGMASK(tmpset)) {
		PROC_UNLOCK(p);
		RPC_RETURN(EINTR);
	}
	PROC_UNLOCK(p);
#endif
	RPC_RETURN(0);
}

/*
 * Lock a socket against others. Necessary for STREAM sockets to ensure you
 * get an entire rpc request/reply and also to avoid race conditions between
 * the processes with nfs requests in progress when a reconnect is necessary.
 */
static int
rpcclnt_sndlock(flagp, task)
	int            *flagp;
	struct rpctask *task;
{
	RPC_EXEC_CTX p;
	int             slpflag = 0, slptimeo = 0;

	if (task) {
		p = task->r_td;
		if (task->r_rpcclnt->rc_flag & RPCCLNT_INT)
			slpflag = PCATCH;
	} else
		p = NULL;
	while (*flagp & RPCCLNT_SNDLOCK) {
		if (rpcclnt_sigintr(task->r_rpcclnt, task, p))
			RPC_RETURN(EINTR);
		*flagp |= RPCCLNT_WANTSND;
		(void)tsleep((caddr_t) flagp, slpflag | (PZERO - 1), "rpcsndlck",
			     slptimeo);
		if (slpflag == PCATCH) {
			slpflag = 0;
			slptimeo = 2 * hz;
		}
	}
	*flagp |= RPCCLNT_SNDLOCK;
	RPC_RETURN(0);
}

/*
 * Unlock the stream socket for others.
 */
static void
rpcclnt_sndunlock(flagp)
	int            *flagp;
{

	if ((*flagp & RPCCLNT_SNDLOCK) == 0)
		panic("rpc sndunlock");
	*flagp &= ~RPCCLNT_SNDLOCK;
	if (*flagp & RPCCLNT_WANTSND) {
		*flagp &= ~RPCCLNT_WANTSND;
		wakeup((caddr_t) flagp);
	}
}

static int
rpcclnt_rcvlock(task)
	struct rpctask *task;
{
	int            *flagp = &task->r_rpcclnt->rc_flag;
	int             slpflag, slptimeo = 0;

	if (*flagp & RPCCLNT_INT)
		slpflag = PCATCH;
	else
		slpflag = 0;
	while (*flagp & RPCCLNT_RCVLOCK) {
		if (rpcclnt_sigintr(task->r_rpcclnt, task, task->r_td))
			RPC_RETURN(EINTR);
		*flagp |= RPCCLNT_WANTRCV;
		(void)tsleep((caddr_t) flagp, slpflag | (PZERO - 1), "rpcrcvlk",
			     slptimeo);
		if (slpflag == PCATCH) {
			slpflag = 0;
			slptimeo = 2 * hz;
		}
	}
	*flagp |= RPCCLNT_RCVLOCK;
	RPC_RETURN(0);
}

/*
 * Unlock the stream socket for others.
 */
static void
rpcclnt_rcvunlock(flagp)
	int            *flagp;
{

	if ((*flagp & RPCCLNT_RCVLOCK) == 0)
		panic("nfs rcvunlock");
	*flagp &= ~RPCCLNT_RCVLOCK;
	if (*flagp & RPCCLNT_WANTRCV) {
		*flagp &= ~RPCCLNT_WANTRCV;
		wakeup((caddr_t) flagp);
	}
}

#if 0
/*
 * Check for badly aligned mbuf data areas and realign data in an mbuf list
 * by copying the data areas up, as required.
 */
void
rpcclnt_realign(m, hsiz)
	struct mbuf    *m;
	int             hsiz;
{
	struct mbuf    *m2;
	int             siz, mlen, olen;
	caddr_t         tcp, fcp;
	struct mbuf    *mnew;

	while (m) {
		/*
		 * This never happens for UDP, rarely happens for TCP but
		 * frequently happens for iso transport.
		 */
		if ((m->m_len & 0x3) || (mtod(m, long)&0x3)) {
			olen = m->m_len;
			fcp = mtod(m, caddr_t);
			if ((long)fcp & 0x3) {
				if (m->m_flags & M_PKTHDR)
					m_tag_delete_chain(m, NULL);
				m->m_flags &= ~M_PKTHDR;
				if (m->m_flags & M_EXT)
					m->m_data = m->m_ext.ext_buf +
						((m->m_ext.ext_size - olen) & ~0x3);
				else
					m->m_data = m->m_dat;
			}
			m->m_len = 0;
			tcp = mtod(m, caddr_t);
			mnew = m;
			m2 = m->m_next;

			/*
			 * If possible, only put the first invariant part of
			 * the RPC header in the first mbuf.
			 */
			mlen = M_TRAILINGSPACE(m);
			if (olen <= hsiz && mlen > hsiz)
				mlen = hsiz;

			/* Loop through the mbuf list consolidating data. */
			while (m) {
				while (olen > 0) {
					if (mlen == 0) {
						if (m2->m_flags & M_PKTHDR)
							m_tag_delete_chain(m2, NULL);
						m2->m_flags &= ~M_PKTHDR;
						if (m2->m_flags & M_EXT)
							m2->m_data = m2->m_ext.ext_buf;
						else
							m2->m_data = m2->m_dat;
						m2->m_len = 0;
						mlen = M_TRAILINGSPACE(m2);
						tcp = mtod(m2, caddr_t);
						mnew = m2;
						m2 = m2->m_next;
					}
					siz = min(mlen, olen);
					if (tcp != fcp)
						bcopy(fcp, tcp, siz);
					mnew->m_len += siz;
					mlen -= siz;
					olen -= siz;
					tcp += siz;
					fcp += siz;
				}
				m = m->m_next;
				if (m) {
					olen = m->m_len;
					fcp = mtod(m, caddr_t);
				}
			}

			/*
			 * Finally, set m_len == 0 for any trailing mbufs
			 * that have been copied out of.
			 */
			while (m2) {
				m2->m_len = 0;
				m2 = m2->m_next;
			}
			return;
		}
		m = m->m_next;
	}
}
#else
static void
rpcclnt_realign(struct mbuf **pm, int hsiz)
{
	struct mbuf *m;
	struct mbuf *n = NULL;
	int off = 0;

	RPCDEBUG("in rpcclnt_realign()");

	while ((m = *pm) != NULL) {
	    if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) {
	        MGET(n, M_TRYWAIT, MT_DATA);
	        if (m->m_len >= MINCLSIZE) {
	            MCLGET(n, M_TRYWAIT);
	        }
	        n->m_len = 0;
	        break;
	    }
	    pm = &m->m_next;
	}

	/*
	* If n is non-NULL, loop on m copying data, then replace the
	* portion of the chain that had to be realigned.
	*/
	if (n != NULL) {
	    while (m) {
	        m_copyback(n, off, m->m_len, mtod(m, caddr_t));
	        off += m->m_len;
	        m = m->m_next;
	    }
	    m_freem(*pm);
	    *pm = n;
	}

	RPCDEBUG("leave rpcclnt_realign()");
}
#endif

static int
rpcclnt_msg(p, server, msg)
	RPC_EXEC_CTX   p;
	const char     *server;
	char           *msg;
{
#ifdef __OpenBSD__
	tpr_t           tpr;
	struct proc    *pr = p;

	if (p)
		tpr = tprintf_open(p);
	else
		tpr = NULL;
	tprintf(tpr, "rpc server %s: %s\n", server, msg);
	tprintf_close(tpr);
	RPC_RETURN(0);
#else
	tprintf(p ? p->td_proc : NULL, LOG_INFO,
		"nfs server %s: %s\n", server, msg);
	RPC_RETURN(0);
#endif
}

/*
 * Build the RPC header and fill in the authorization info. The authorization
 * string argument is only used when the credentials come from outside of the
 * kernel (AUTH_KERB). (likewise, the ucred is only used when inside the
 * kernel) Returns the head of the mbuf list.
 */
static struct mbuf    *
rpcclnt_buildheader(rc, procid, mrest, mrest_len, xidp, mheadend, cred)
	struct rpcclnt *rc;
	int             procid;
	struct mbuf    *mrest;
	u_int32_t       mrest_len;
	int            *xidp;
	struct mbuf   **mheadend;
	struct ucred * cred;
{
	/* register */ struct mbuf *mb;
	register u_int32_t *tl;
	/* register */ caddr_t bpos;
	struct mbuf *mreq, *mb2;
	int error;

	MGETHDR(mb, M_TRYWAIT, MT_DATA);
	if (6 * RPCX_UNSIGNED >= MINCLSIZE) {
		MCLGET(mb, M_TRYWAIT);
	} else if (6 * RPCX_UNSIGNED < MHLEN) {
		MH_ALIGN(mb, 6 * RPCX_UNSIGNED);
	} else {
	  	RPCDEBUG("mbuf too small");
		panic("cheap bailout");
	}
	mb->m_len = 0;
	mreq = mb;
	bpos = mtod(mb, caddr_t);

	/*
	 * First the RPC header.
	 */
	rpcm_build(tl, u_int32_t *, 6 * RPCX_UNSIGNED);

	/* Get a new (non-zero) xid */
	if ((rpcclnt_xid == 0) && (rpcclnt_xid_touched == 0)) {
		rpcclnt_xid = arc4random();
		rpcclnt_xid_touched = 1;
	} else {
		while ((*xidp = arc4random() % 256) == 0);
		rpcclnt_xid += *xidp;
	}

	/* XXX: funky... */
	*tl++ = *xidp = txdr_unsigned(rpcclnt_xid);

	*tl++ = rpc_call;
	*tl++ = rpc_vers;
	*tl++ = txdr_unsigned(rc->rc_prog->prog_id);
	*tl++ = txdr_unsigned(rc->rc_prog->prog_version);
	*tl++ = txdr_unsigned(procid);

	if ((error = rpcauth_buildheader(rc->rc_auth, cred, &mb, &bpos))) {
		RPCDEBUG("rpcauth_buildheader failed %d", error);
		return NULL;
	}

	mb->m_next = mrest;
	*mheadend = mb;
	mreq->m_pkthdr.len = m_length(mreq, NULL);
	mreq->m_pkthdr.rcvif = NULL;
	return (mreq);
}

/*
 * Help break down an mbuf chain by setting the first siz bytes contiguous
 * pointed to by returned val. This is used by the macros rpcm_dissect and
 * rpcm_dissecton for tough cases. (The macros use the vars. dpos and dpos2)
 */
static int
rpcm_disct(mdp, dposp, siz, left, cp2)
	struct mbuf   **mdp;
	caddr_t        *dposp;
	int             siz;
	int             left;
	caddr_t        *cp2;
{
	struct mbuf    *mp, *mp2;
	int             siz2, xfer;
	caddr_t         p;

	mp = *mdp;
	while (left == 0) {
		*mdp = mp = mp->m_next;
		if (mp == NULL)
			RPC_RETURN(EBADRPC);
		left = mp->m_len;
		*dposp = mtod(mp, caddr_t);
	}
	if (left >= siz) {
		*cp2 = *dposp;
		*dposp += siz;
	} else if (mp->m_next == NULL) {
		RPC_RETURN(EBADRPC);
	} else if (siz > MHLEN) {
		panic("rpc S too big");
	} else {
		MGET(mp2, M_TRYWAIT, MT_DATA);
		mp2->m_next = mp->m_next;
		mp->m_next = mp2;
		mp->m_len -= left;
		mp = mp2;
		*cp2 = p = mtod(mp, caddr_t);
		bcopy(*dposp, p, left);	/* Copy what was left */
		siz2 = siz - left;
		p += left;
		mp2 = mp->m_next;
		/* Loop around copying up the siz2 bytes */
		while (siz2 > 0) {
			if (mp2 == NULL)
				RPC_RETURN(EBADRPC);
			xfer = (siz2 > mp2->m_len) ? mp2->m_len : siz2;
			if (xfer > 0) {
				bcopy(mtod(mp2, caddr_t), p, xfer);
				RPCMADV(mp2, xfer);
				mp2->m_len -= xfer;
				p += xfer;
				siz2 -= xfer;
			}
			if (siz2 > 0)
				mp2 = mp2->m_next;
		}
		mp->m_len = siz;
		*mdp = mp2;
		*dposp = mtod(mp2, caddr_t);
	}
	RPC_RETURN(0);
}

static u_int32_t
rpcclnt_proct(rpc, procid)
	struct rpcclnt *rpc;
	u_int32_t       procid;
{
	if (rpc->rc_proctlen != 0 && rpc->rc_proct != NULL &&
	    procid < rpc->rc_proctlen) {
		return rpc->rc_proct[procid];
	}
	return (0);
}

static int
rpc_adv(mdp, dposp, offs, left)
	struct mbuf   **mdp;
	caddr_t        *dposp;
	int             offs;
	int             left;
{
	struct mbuf    *m;
	int             s;

	m = *mdp;
	s = left;
	while (s < offs) {
		offs -= s;
		m = m->m_next;
		if (m == NULL)
			RPC_RETURN(EBADRPC);
		s = m->m_len;
	}
	*mdp = m;
	*dposp = mtod(m, caddr_t) + offs;
	RPC_RETURN(0);
}

int
rpcclnt_cancelreqs(rpc)
	struct rpcclnt *rpc;
{
	struct rpctask *task;
	int             i, s;

	s = splnet();
	TAILQ_FOREACH(task, &rpctask_q, r_chain) {
		if (rpc != task->r_rpcclnt || task->r_mrep != NULL ||
		    (task->r_flags & R_SOFTTERM))
			continue;
		rpcclnt_softterm(task);
	}
	splx(s);

	for (i = 0; i < 30; i++) {
		s = splnet();
		TAILQ_FOREACH(task, &rpctask_q, r_chain) {
			if (rpc == task->r_rpcclnt)
				break;
		}
		splx(s);
		if (task == NULL)
			return (0);
		tsleep(&lbolt, PSOCK, "nfscancel", 0);
	}
	return (EBUSY);
}

static void
rpcclnt_softterm(struct rpctask * task)
{
	task->r_flags |= R_SOFTTERM;
	if (task->r_flags & R_SENT) {
		task->r_rpcclnt->rc_sent -= RPC_CWNDSCALE;
		task->r_flags &= ~R_SENT;
	}
}

#ifndef __OpenBSD__
/* called by rpcclnt_get() */
void
rpcclnt_create(struct rpcclnt ** rpc)
{
	MALLOC(*rpc, struct rpcclnt *, sizeof(struct rpcclnt), M_RPC, M_WAITOK | M_ZERO);
}

/* called by rpcclnt_put() */
void
rpcclnt_destroy(struct rpcclnt * rpc)
{
	if (rpc != NULL) {
		FREE(rpc, M_RPC);
	} else {
		RPCDEBUG("attempting to free a NULL rpcclnt (not dereferenced)");
	}
}
#endif				/* !__OpenBSD__ */

/* XXX: add a lock around the auth structure in struct rpcclnt and make this
 * call safe for calling durring a connection */
static int
rpcauth_buildheader(struct rpc_auth * auth, struct ucred * cred, struct mbuf ** mhdr, caddr_t * bp)
{
	size_t authsiz, verfsiz;
	uint32_t mlen, grpsiz;
	register struct mbuf *mb, *mb2;
	caddr_t bpos;
	register u_int32_t *tl;
	register int i;

	if (auth == NULL || mhdr == NULL)
	  return EFAULT;

	switch (auth->auth_type) {
	case RPCAUTH_NULL:
	  	authsiz = 0;
		verfsiz = 0;
	break;
	case RPCAUTH_UNIX:
		authsiz = (5 + cred->cr_ngroups) * RPCX_UNSIGNED;
		verfsiz = 0;
	break;
	default:
		return EPROTONOSUPPORT;
	break;
	};

	mlen = rpcm_rndup(authsiz) + rpcm_rndup(verfsiz) + 4 * RPCX_UNSIGNED;

	mb = *mhdr;
	bpos = *bp;

	rpcm_build(tl, u_int32_t *, mlen);

	*bp = bpos;
	*mhdr = mb;

	*tl++ = txdr_unsigned(auth->auth_type);
	*tl++ = txdr_unsigned(authsiz);
	switch (auth->auth_type) {
	case RPCAUTH_UNIX:
	 	*tl++ = 0;
	 	*tl++ = 0;

		*tl++ = txdr_unsigned(cred->cr_uid);
		*tl++ = txdr_unsigned(cred->cr_groups[0]);
		grpsiz = cred->cr_ngroups;
		*tl++ = txdr_unsigned(grpsiz);
		/* XXX: groups[0] is already sent... */
		for (i = 0 ; i < grpsiz ; i++) {
			 *tl++ = txdr_unsigned(cred->cr_groups[i]);
		}

		/* null verification header */
		*tl++ = txdr_unsigned(RPCAUTH_NULL);
		*tl++ = 0;
	break;
	case RPCAUTH_NULL:
		/* just a null verf header */
		*tl++ = txdr_unsigned(RPCAUTH_NULL);
		*tl = 0;
	break;
	default:
		panic("inconsistent rpc auth type");
	break;
	}

	return 0;
}


text:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using AutoFixture.NUnit3;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.UnitTests.AutoFixture;

namespace Umbraco.Tests.Services;

[TestFixture]
internal class ContentVersionCleanupServiceTest
{
    [Test]
    [AutoMoqData]
    public void PerformContentVersionCleanup_Always_RespectsDeleteRevisionsCancellation(
        [Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
        [Frozen] Mock<IContentVersionCleanupPolicy> policy,
        [Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
        List<ContentVersionMeta> someHistoricVersions,
        DateTime aDateTime,
        ContentVersionService sut)
    {
        documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
            .Returns(someHistoricVersions);

        eventAggregator.Setup(x => x.PublishCancelable(It.IsAny<ContentDeletingVersionsNotification>()))
            .Returns(true);

        policy.Setup(x => x.Apply(aDateTime, someHistoricVersions))
            .Returns(someHistoricVersions);

        // # Act
        var report = sut.PerformContentVersionCleanup(aDateTime);

        Assert.Multiple(() =>
        {
            eventAggregator.Verify(
                x => x.PublishCancelable(
                    It.IsAny<ContentDeletingVersionsNotification>()),
                Times.Exactly(someHistoricVersions.Count));
            Assert.AreEqual(0, report.Count);
        });
    }

    [Test]
    [AutoMoqData]
    public void PerformContentVersionCleanup_Always_FiresDeletedVersionsForEachDeletedVersion(
        [Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
        [Frozen] Mock<IContentVersionCleanupPolicy> policy,
        [Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
        List<ContentVersionMeta> someHistoricVersions,
        DateTime aDateTime,
        ContentVersionService sut)
    {
        documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
            .Returns(someHistoricVersions);

        eventAggregator
            .Setup(x => x.PublishCancelable(It.IsAny<ICancelableNotification>()))
            .Returns(false);

        policy.Setup(x => x.Apply(aDateTime, someHistoricVersions))
            .Returns(someHistoricVersions);

        // # Act
        sut.PerformContentVersionCleanup(aDateTime);

        eventAggregator.Verify(x => x.Publish(It.IsAny<ContentDeletedVersionsNotification>()), Times.Exactly(someHistoricVersions.Count));
    }

    [Test]
    [AutoMoqData]
    public void PerformContentVersionCleanup_Always_ReturnsReportOfDeletedItems(
        [Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
        [Frozen] Mock<IContentVersionCleanupPolicy> policy,
        [Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
        List<ContentVersionMeta> someHistoricVersions,
        DateTime aDateTime,
        ContentVersionService sut)
    {
        documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
            .Returns(someHistoricVersions);

        eventAggregator
            .Setup(x => x.PublishCancelable(It.IsAny<ICancelableNotification>()))
            .Returns(false);

        // # Act
        var report = sut.PerformContentVersionCleanup(aDateTime);

        Assert.Multiple(() =>
        {
            Assert.Greater(report.Count, 0);
            Assert.AreEqual(someHistoricVersions.Count, report.Count);
        });
    }

    [Test]
    [AutoMoqData]
    public void PerformContentVersionCleanup_Always_AdheresToCleanupPolicy(
        [Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
        [Frozen] Mock<IContentVersionCleanupPolicy> policy,
        [Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
        List<ContentVersionMeta> someHistoricVersions,
        DateTime aDateTime,
        ContentVersionService sut)
    {
        documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
            .Returns(someHistoricVersions);

        eventAggregator
            .Setup(x => x.PublishCancelable(It.IsAny<ICancelableNotification>()))
            .Returns(false);

        policy.Setup(x => x.Apply(It.IsAny<DateTime>(), It.IsAny<IEnumerable<ContentVersionMeta>>()))
            .Returns<DateTime, IEnumerable<ContentVersionMeta>>((_, items) => items.Take(1));

        // # Act
        var report = sut.PerformContentVersionCleanup(aDateTime);

        Debug.Assert(someHistoricVersions.Count > 1);

        Assert.Multiple(() =>
        {
            policy.Verify(x => x.Apply(aDateTime, someHistoricVersions), Times.Once);
            Assert.AreEqual(someHistoricVersions.First(), report.Single());
        });
    }

    /// <remarks>
    ///     For v9 this just needs a rewrite, no static events, no service location etc
    /// </remarks>
    [Test]
    [AutoMoqData]
    public void PerformContentVersionCleanup_HasVersionsToDelete_CallsDeleteOnRepositoryWithFilteredSet(
        [Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
        [Frozen] Mock<IContentVersionCleanupPolicy> policy,
        [Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
        List<ContentVersionMeta> someHistoricVersions,
        DateTime aDateTime,
        ContentVersionService sut)
    {
        documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
            .Returns(someHistoricVersions);

        eventAggregator
            .Setup(x => x.PublishCancelable(It.IsAny<ICancelableNotification>()))
            .Returns(false);

        var filteredSet = someHistoricVersions.Take(1);

        policy.Setup(x => x.Apply(It.IsAny<DateTime>(), It.IsAny<IEnumerable<ContentVersionMeta>>()))
            .Returns<DateTime, IEnumerable<ContentVersionMeta>>((_, items) => filteredSet);

        // # Act
        sut.PerformContentVersionCleanup(aDateTime);

        Debug.Assert(someHistoricVersions.Any());

        var expectedId = filteredSet.First().VersionId;

        documentVersionRepository.Verify(
            x => x.DeleteVersions(It.Is<IEnumerable<int>>(y => y.Single() == expectedId)),
            Times.Once);
    }
}


text:
from FoodConfigParser import FoodConfigParser
from Database import Database
from NutrientsTable import NutrientsTable, CustomFoods
from NutrientList import FATTAGS

class Foodset:
    """
    Foodset is one collection of foods to be analayzed.
    """

    def __init__(self, i):
        self.datafile = i
        self.foods = []
        self.initialize_foods()

    def initialize_foods(self):
        cf = FoodConfigParser()
        cf.read(self.datafile)
        for s in cf.sections:
            try:
                food = Food()
                food.initialize (s.dict)
                self.foods.append(food)
            except KeyError:
                pass

    def total_fat_g(self):
        amt = 0
        for tag in  FATTAGS:
            for f in self.foods:
                if tag in f.nutrients:
                    amt = amt + f.nutrients[tag]
        return float(amt)

    def total_prot_g(self):
        amt = 0
        tag = 'PROCNT'
        for f in self.foods:
            if tag in f.nutrients:
                amt = amt + f.nutrients[tag]
        return float(amt)

    def sat_fat_g(self):
        return self.get_total_of_("FASAT")

    def get_total_of_(self, s):
        return self.get_nutrient_total(s)

    def fruit_and_veg_total(self):
        running_total = 0
        for f in self.foods:
            if not CustomFoods().has_nutrition_facts(f.fullname):
                if Database().is_fruit_or_veg(f):
                    running_total = running_total + f.amt_g
        return running_total

    def get_nutrient_total(self, nutrient):
        total = 0
        for f in self.foods:
            if nutrient in f.nutrients:
                if None != f.nutrients[nutrient]:
                    total = total + f.nutrients[nutrient]
        return float(total)

class Food(object):
    def __init__(self):
        setattr(self, "fullname", None)
        setattr(self, "friendly", None)
        setattr(self, "amt_g", None)
        setattr(self, "ndbno", None)
        setattr(self, "foodgroup_code", None)

    def initialize(self,section):
        for key in section:
            self.set_attribute(key, section)
        if self.fullname is None:
            raise KeyError
        self.nutrients = NutrientsTable(self)
        Database().get_food_ndbno(self)

    def set_attribute(self, key, section):
        name = None
        value = None
        mapping = {'usda_name': 'fullname', 'amt': 'amt_g',
                   'friendly_name': 'friendly'}
        if key not in mapping:
            return
        name = mapping[key]
        value = section[key]
        if key == 'amt':
            value = float(value)
        if name:
            setattr(self, name, value)

if __name__ == '__main__':
    pass