From da77a6007d4bbd1cd6ea5dc9799aa240cc250a94 Mon Sep 17 00:00:00 2001 From: Galen Ma Date: Fri, 8 Apr 2016 16:02:59 +0800 Subject: [PATCH] android fix rlimit https://github.com/warmcat/libwebsockets/issues/488 --- lib/context.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/context.c b/lib/context.c index 46ff505..8a96518 100644 --- a/lib/context.c +++ b/lib/context.c @@ -353,6 +353,10 @@ lws_create_context(struct lws_context_creation_info *info) int pid_daemon = get_daemonize_pid(); #endif int n, m; +#if defined(__ANDROID__) + struct rlimit rt; +#endif + lwsl_notice("Initial logging level %d\n", log_level); lwsl_notice("Libwebsockets version: %s\n", library_version); @@ -390,7 +394,16 @@ lws_create_context(struct lws_context_creation_info *info) lwsl_notice(" Started with daemon pid %d\n", pid_daemon); } #endif - context->max_fds = getdtablesize(); +#if defined(__ANDROID__) + n = getrlimit ( RLIMIT_NOFILE,&rt); + if (-1 == n) { + lwsl_err("Get RLIMIT_NOFILE failed!\n"); + return NULL; + } + context->max_fds = rt.rlim_cur; +#else + context->max_fds = getdtablesize(); +#endif if (info->count_threads) context->count_threads = info->count_threads; -- 2.7.4