this function tries to raise the file descriptor limit to the requested number. It returns the actual file descriptor limit (which may be more or less than nMinFD)
| 759 | // this function tries to raise the file descriptor limit to the requested number. |
| 760 | // It returns the actual file descriptor limit (which may be more or less than nMinFD) |
| 761 | int RaiseFileDescriptorLimit(int nMinFD) { |
| 762 | #if defined(WIN32) |
| 763 | return 2048; |
| 764 | #else |
| 765 | struct rlimit limitFD; |
| 766 | if (getrlimit(RLIMIT_NOFILE, &limitFD) != -1) { |
| 767 | if (limitFD.rlim_cur < (rlim_t)nMinFD) { |
| 768 | limitFD.rlim_cur = nMinFD; |
| 769 | if (limitFD.rlim_cur > limitFD.rlim_max) limitFD.rlim_cur = limitFD.rlim_max; |
| 770 | setrlimit(RLIMIT_NOFILE, &limitFD); |
| 771 | getrlimit(RLIMIT_NOFILE, &limitFD); |
| 772 | } |
| 773 | return limitFD.rlim_cur; |
| 774 | } |
| 775 | return nMinFD; // getrlimit failed, assume it's fine |
| 776 | #endif |
| 777 | } |
| 778 | |
| 779 | // this function tries to make a particular range of a file allocated (corresponding to disk space) |
| 780 | // it is advisory, and the range specified in the arguments will never contain live data |