mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 03:47:53 +08:00
Add set_fdlimit in fiber.hpp
This commit is contained in:
parent
5919f5460d
commit
3e7a588d60
@ -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 来启动协程调度器
|
||||
|
@ -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 */)
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user