Пример #1
0
  /**
   * get a socket option
   *
   * @param socket socket descriptor
   * @param level Socket.SOL_SOCKET, etc.
   * @param option_name
   * @return socket option value
   * @throws IOException on error
   */
  public int getSockOpt(int socket, int level, int option_name) throws IOException {
    IntByReference value = new IntByReference(0);
    IntByReference opt_len = new IntByReference(4);
    if (DEBUG) {
      System.out.println("getsockopt(" + socket + ", " + level + ", " + option_name + ")");
    }

    int err = sockets.getsockopt(socket, level, option_name, value, opt_len);
    if (DEBUG) {
      System.out.println(
          "    returned value: " + value.getValue() + ", size: " + opt_len.getValue());
    }

    int result = value.getValue();
    value.free();
    if (false) Assert.that(opt_len.getValue() == 4);
    opt_len.free();
    LibCUtil.errCheckNeg(err);
    return result;
  }