Beispiel #1
0
  /**
   * set a socket option
   *
   * @param socket socket descriptor
   * @param level Socket.SOL_SOCKET, etc.
   * @param option_name
   * @param option_value new value
   * @throws IOException on error
   */
  public void setSockOpt(int socket, int level, int option_name, int option_value)
      throws IOException {
    IntByReference value = new IntByReference(option_value);
    if (false) Assert.that(option_value == value.getValue());
    if (DEBUG) {
      System.out.println(
          "setSockOpt(" + socket + ", " + level + ", " + option_name + ", " + option_value + ")");
    }
    int err = sockets.setsockopt(socket, level, option_name, value, 4);

    if (false) Assert.that(option_value == value.getValue());
    value.free();
    LibCUtil.errCheckNeg(err);

    if (DEBUG) {
      int newValue = getSockOpt(socket, level, option_name);
      if (option_value != newValue) {
        System.out.println(
            "FAILED: setSockOpt("
                + socket
                + ", "
                + level
                + ", "
                + option_name
                + ", "
                + option_value
                + ")");
        System.err.println("   Ended with: " + newValue);
      }
    }
  }
Beispiel #2
0
  /**
   * get a socket option
   *
   * @param socket socket descriptor
   * @param option_name
   * @throws IOException on error
   */
  public int getSockOpt(int socket, int option_name) throws IOException {
    IntByReference value = new IntByReference(0);
    IntByReference opt_len = new IntByReference(4);
    if (DEBUG) {
      System.out.println("getsockopt(" + socket + ", " + option_name + ")");
    }

    int err = sockets.getsockopt(socket, Socket.SOL_SOCKET, option_name, value, opt_len);
    int result = value.getValue();
    value.free();
    if (false) Assert.that(opt_len.getValue() == 4);
    opt_len.free();
    LibCUtil.errCheckNeg(err);
    return result;
  }