From 5ac4a7c2a118e58a8cdfbc8c08ecb30f5ecd012b Mon Sep 17 00:00:00 2001 From: Jin-Seong Kim Date: Mon, 10 Jul 2017 17:29:55 +0900 Subject: [PATCH] examples/libcoap : increase pthread stack size to support security This commit is to increase pthread stack size to support security - to support security through mbedTLS libarary, pthread stack size should be (16 * 1024) at least Change-Id: Ic01b803dcb0b4bf3d6e4a0c2e8f3b6e5546ab434 Signed-off-by: Jin-Seong Kim --- apps/examples/libcoap_client/libcoap-client.c | 2 +- apps/examples/libcoap_server/libcoap-server.c | 68 ++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/apps/examples/libcoap_client/libcoap-client.c b/apps/examples/libcoap_client/libcoap-client.c index 59e4171..6c0df04 100644 --- a/apps/examples/libcoap_client/libcoap-client.c +++ b/apps/examples/libcoap_client/libcoap-client.c @@ -33,7 +33,7 @@ #if defined (__TINYARA__) #define COAP_CLIENT_SCHED_PRI 100 #define COAP_CLIENT_SCHED_POLICY SCHED_RR -#define COAP_CLIENT_STACK_SIZE (1024 * 8) +#define COAP_CLIENT_STACK_SIZE (1024 * 16) /* used for sending input arguments to pthread */ struct coap_client_input { diff --git a/apps/examples/libcoap_server/libcoap-server.c b/apps/examples/libcoap_server/libcoap-server.c index 7c9737a..20f3b7a 100644 --- a/apps/examples/libcoap_server/libcoap-server.c +++ b/apps/examples/libcoap_server/libcoap-server.c @@ -41,6 +41,16 @@ #endif #if defined(__TINYARA__) +#define COAP_SERVER_SCHED_PRI 100 +#define COAP_SERVER_SCHED_POLICY SCHED_RR +#define COAP_SERVER_STACK_SIZE (1024 * 16) + +/* used for sending input arguments to pthread */ +struct coap_server_input { + int argc; + char **argv; +}; + #ifndef FD_SETSIZE #define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) #endif @@ -348,7 +358,7 @@ finish: } #if defined (__TINYARA__) -int coap_server_test_main(int argc, char **argv) +int coap_server_test_run(void *arg) #else int main(int argc, char **argv) #endif @@ -365,6 +375,14 @@ int main(int argc, char **argv) int invalid_opt = 0; coap_log_t log_level = LOG_WARNING; +#if defined (__TINYARA__) + int argc; + char **argv; + + argc = ((struct coap_server_input *)arg)->argc; + argv = ((struct coap_server_input *)arg)->argv; +#endif + while ((opt = getopt(argc, argv, "A:p:v:Q")) != -1) { switch (opt) { case 'A': @@ -493,3 +511,51 @@ int main(int argc, char **argv) return 0; } + +#if defined (__TINYARA__) +int coap_server_test_main(int argc, char **argv) +{ + int status; + + pthread_t tid; + pthread_attr_t attr; + struct sched_param sparam; + struct coap_server_input arg; + + status = pthread_attr_init(&attr); + + if (status != 0) { + printf("coap_server_test_main : failed to start coap-client\n"); + return -1; + } + + sparam.sched_priority = COAP_SERVER_SCHED_PRI; + if ((status = pthread_attr_setschedparam(&attr, &sparam)) != 0) { + printf("coap_server_test_main : failed pthread_attr_setschedparam, errno %d\n", errno); + return -1; + } + + if ((status = pthread_attr_setschedpolicy(&attr, COAP_SERVER_SCHED_POLICY)) != 0) { + printf("coap_server_test_main : failed pthread_attr_setschedpolicy, errno %d\n", errno); + return -1; + } + + if ((status = pthread_attr_setstacksize(&attr, COAP_SERVER_STACK_SIZE)) != 0) { + printf("coap_server_test_main : failed pthread_attr_setstacksize, errno %d\n", errno); + return -1; + } + + arg.argc = argc; + arg.argv = argv; + + if ((status = pthread_create(&tid, &attr, (pthread_startroutine_t)coap_server_test_run, &arg)) < 0) { + printf("coap_server_test_main : failed to run coap-client, errno %d\n", errno); + return -1; + } + + pthread_setname_np(tid, "coap-server-test"); + pthread_join(tid, NULL); + + return 0; +} +#endif /* __TINYARA__ */ -- 2.7.4