| ... | @@ -45,6 +45,7 @@ typedef SSIZE_T ssize_t; | ... | @@ -45,6 +45,7 @@ typedef SSIZE_T ssize_t; |
| 45 | #include <sys/types.h> | 45 | #include <sys/types.h> |
| 46 | #include <sys/stat.h> | 46 | #include <sys/stat.h> |
| 47 | #include <sys/wait.h> | 47 | #include <sys/wait.h> |
| | 48 | #include <sys/resource.h> |
| 48 | #include <fcntl.h> | 49 | #include <fcntl.h> |
| 49 | #include <limits.h> | 50 | #include <limits.h> |
| 50 | #include <spawn.h> | 51 | #include <spawn.h> |
| ... | @@ -1374,6 +1375,29 @@ int os_init(void) { | ... | @@ -1374,6 +1375,29 @@ int os_init(void) { |
| 1374 | #elif defined(__MACH__) | 1375 | #elif defined(__MACH__) |
| 1375 | host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &macos_monotonic_clock); | 1376 | host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &macos_monotonic_clock); |
| 1376 | host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &macos_calendar_clock); | 1377 | host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &macos_calendar_clock); |
| | 1378 | #endif |
| | 1379 | #if defined(ZIG_OS_POSIX) |
| | 1380 | // Raise the open file descriptor limit. |
| | 1381 | // Code lifted from node.js |
| | 1382 | struct rlimit lim; |
| | 1383 | if (getrlimit(RLIMIT_NOFILE, &lim) == 0 && lim.rlim_cur != lim.rlim_max) { |
| | 1384 | // Do a binary search for the limit. |
| | 1385 | rlim_t min = lim.rlim_cur; |
| | 1386 | rlim_t max = 1 << 20; |
| | 1387 | // But if there's a defined upper bound, don't search, just set it. |
| | 1388 | if (lim.rlim_max != RLIM_INFINITY) { |
| | 1389 | min = lim.rlim_max; |
| | 1390 | max = lim.rlim_max; |
| | 1391 | } |
| | 1392 | do { |
| | 1393 | lim.rlim_cur = min + (max - min) / 2; |
| | 1394 | if (setrlimit(RLIMIT_NOFILE, &lim)) { |
| | 1395 | max = lim.rlim_cur; |
| | 1396 | } else { |
| | 1397 | min = lim.rlim_cur; |
| | 1398 | } |
| | 1399 | } while (min + 1 < max); |
| | 1400 | } |
| 1377 | #endif | 1401 | #endif |
| 1378 | return 0; | 1402 | return 0; |
| 1379 | } | 1403 | } |