android fix rlimit
authorGalen Ma <galen.ma@github.invalid.com>
Fri, 8 Apr 2016 08:04:58 +0000 (16:04 +0800)
committerAndy Green <andy@warmcat.com>
Fri, 8 Apr 2016 08:04:58 +0000 (16:04 +0800)
https://github.com/warmcat/libwebsockets/issues/488

lib/context.c

index 2574f22..68583ab 100644 (file)
@@ -79,6 +79,10 @@ lws_create_context(struct lws_context_creation_info *info)
 #endif
        char *p;
        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);
@@ -115,7 +119,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;