Add set_fdlimit in fiber.hpp

This commit is contained in:
zhengshuxin 2023-06-21 10:56:02 +08:00
parent 5919f5460d
commit 3e7a588d60
3 changed files with 21 additions and 3 deletions

View File

@ -133,6 +133,13 @@ public:
*/
static void stdout_open(bool on);
/**
*
* @param max {int} >= 0
* @return {int}
*/
static int set_fdlimit(int max);
/**
*
* schedule schedule_with

View File

@ -308,6 +308,11 @@ void fiber::stdout_open(bool on)
acl_fiber_msg_stdout_enable(on ? 1 : 0);
}
int fiber::set_fdlimit(int max)
{
return acl_fiber_set_fdlimit(max);
}
ACL_FIBER* fiber::fiber_create(void (*fn)(ACL_FIBER*, void*), void* ctx,
size_t stack_size, bool share_stack /* false */)
{

View File

@ -47,18 +47,18 @@ static void fiber4(const acl::string& buf)
static void usage(const char* procname)
{
printf("usage: %s -h [help] -n fibers_count -S\r\n", procname);
printf("usage: %s -h [help] -n fibers_count -m maxfd -S\r\n", procname);
}
int main(int argc, char *argv[])
{
int ch, n = 10;
int ch, n = 10, maxfd = 0;
bool share_stack = false;
acl::acl_cpp_init();
acl::log::stdout_open(true);
while ((ch = getopt(argc, argv, "hn:S")) > 0) {
while ((ch = getopt(argc, argv, "hn:m:S")) > 0) {
switch (ch) {
case 'h':
usage(argv[0]);
@ -66,6 +66,9 @@ int main(int argc, char *argv[])
case 'n':
n = atoi(optarg);
break;
case 'm':
maxfd = atoi(optarg);
break;
case 'S':
share_stack = true;
break;
@ -74,6 +77,9 @@ int main(int argc, char *argv[])
}
}
int ret = acl::fiber::set_fdlimit(maxfd);
printf("Current maxfd=%d\r\n", ret);
for (int i = 0; i < n; i++) {
acl::fiber* f = new myfiber();
f->start(share_stack ? 8000 : 32000, share_stack);