Example #1
0
  private void set_blocking_flags(int fd, boolean is_blocking) throws IOException {
    int flags = libc.fcntl(fd, LibC.F_GETFL, 0);
    if (DEBUG) {
      System.out.println("set_blocking_flags: fcntl F_GETFL = " + flags);
    }

    if (flags >= 0) {
      if (is_blocking == true) {
        flags &= ~LibC.O_NONBLOCK;
      } else {
        flags |= LibC.O_NONBLOCK;
      }
      if (DEBUG) {
        System.out.println("set_blocking_flags: calling fcntl F_SETFL flags: " + flags);
      }
      int res = libc.fcntl(fd, LibC.F_SETFL, flags);
      if (res != -1) {
        return;
      }
    }
    throw newError(fd, "set_blocking_flags");
  }