| 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or |
| 3 | * modify it under the terms of the GNU General Public License |
| 4 | * as published by the Free Software Foundation; either version 2 |
| 5 | * of the License, or (at your option) any later version. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 15 | */ |
| 16 | |
| 17 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 18 | #include "rlimit.h"cxx . . $ `<file>/src/common/rlimit.h`/ |
| 19 | |
| 20 | #include <cerrno> |
| 21 | #include <cstring> |
| 22 | |
| 23 | #ifdef HAVE_UNISTD_Hcxx . . $ `build/config.h:7:9`! |
| 24 | # include <unistd.h> |
| 25 | #endif |
| 26 | #ifdef HAVE_SYS_RESOURCE_Hcxx . . $ `build/config.h:33:9`! |
| 27 | # include <sys/resource.h> |
| 28 | #endif |
| 29 | |
| 30 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 31 | #include "common/bn_type.h"cxx . . $ `<file>/src/common/bn_type.h`/ |
| 32 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 33 | |
| 34 | |
| 35 | /* file descriptor limit has different name on BSD and Linux */ |
| 36 | #ifdef RLIMIT_NOFILEcxx . . $ `<external>/1890803886155400780/resource.h:63:9`! |
| 37 | # define RLIM_NUMFILEScxx . . $ `src/common/rlimit.cpp:37:10`! RLIMIT_NOFILEcxx . . $ `<external>/1890803886155400780/resource.h:63:9`! |
| 38 | #else |
| 39 | # ifdef RLIMIT_OFILE |
| 40 | # define RLIM_NUMFILES RLIMIT_OFILE |
| 41 | # endif |
| 42 | #endif |
| 43 | |
| 44 | namespace pvpgncxx . . $ pvpgn/ |
| 45 | { |
| 46 | |
| 47 | extern int get_socket_limitcxx . . $ pvpgn/get_socket_limit(b126dc7c1de90089).(void) |
| 48 | { |
| 49 | int socklimit = 0; |
| 50 | #ifdef HAVE_GETRLIMITcxx . . $ `build/config.h:51:9`! |
| 51 | struct rlimitcxx . . $ rlimit# rlim; |
| 52 | if (getrlimit(RLIM_NUMFILEScxx . . $ `src/common/rlimit.cpp:37:10`!, &rlim) < 0) |
| 53 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "getrlimit returned error: {}", stdcxx . . $ std/::strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 54 | socklimit = rlim.rlim_curcxx . . $ rlimit#rlim_cur.; |
| 55 | #else |
| 56 | /* FIXME: WIN32: somehow get WSAData win32 socket limit here */ |
| 57 | #endif |
| 58 | |
| 59 | #if !(defined HAVE_POLLcxx . . $ `build/config.h:62:9`! || defined HAVE_KQUEUE || defined HAVE_EPOLLcxx . . $ `src/common/setup_before.h:409:10`!) |
| 60 | if (!socklimit || FD_SETSIZE < socklimit) |
| 61 | socklimit = FD_SETSIZE; |
| 62 | #endif |
| 63 | |
| 64 | /* make socket limit smaller than file limit to make sure log files, |
| 65 | db connections and save files will still work */ |
| 66 | socklimit -= 64; |
| 67 | |
| 68 | return socklimit; |
| 69 | } |
| 70 | |
| 71 | } |