macOS Error: DNSSD Crash After Calling fd_set on its Socket in C++

  • C++
  • 1 min read

The error "DNSSD Crash After Calling fd_set on its Socket" occurs on macOS because too many file descriptors are open in C++. This can be solved by increasing the rlimit using the following code:

Solving - macOS Error: DNSSD Crash After Calling fd_set on its Socket

void setup_min_fd(int min_fds)
{
  struct rlimit rlim;
  if (getrlimit(RLIMIT_NOFILE, &rlim) != 0)
    return;

  if (rlim.rlim_cur > rlim_t(min_fds))
    return;

  rlim.rlim_cur = rlim.min_fds;

  setrlimit(RLIMIT_NOFILE, &rlim);
}

See also: