From f4ce5a285167e7656037096f77f04ab80a010453 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 14 Jan 2017 13:00:55 -0800 Subject: Windows TCP now working. There are lots of changes here, mostly stuff we did in support of Windows TCP. However, there are some bugs that were fixed, and we added some new error codes, and generalized the handling of some failures during accept. Windows IPC (NamedPipes) is still missing. --- src/platform/posix/posix_thread.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/platform/posix/posix_thread.c') diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index a429e071..7b4dbbdc 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -28,6 +28,7 @@ static int nni_plat_forked = 0; pthread_condattr_t nni_cvattr; pthread_mutexattr_t nni_mxattr; +static pthread_attr_t nni_pthread_attr; // We open a /dev/null file descriptor so that we can dup2() it to // cause MacOS X to wakeup. This gives us a "safe" close semantic. @@ -189,7 +190,8 @@ nni_plat_thr_init(nni_plat_thr *thr, void (*fn)(void *), void *arg) thr->arg = arg; // POSIX wants functions to return a void *, but we don't care. - rv = pthread_create(&thr->tid, NULL, nni_plat_thr_main, thr); + rv = pthread_create(&thr->tid, &nni_pthread_attr, + nni_plat_thr_main, thr); if (rv != 0) { //nni_printf("pthread_create: %s", strerror(rv)); return (NNG_ENOMEM); @@ -263,9 +265,27 @@ nni_plat_init(int (*helper)(void)) return (NNG_ENOMEM); } + rv = pthread_attr_init(&nni_pthread_attr); + if (rv != 0) { + pthread_mutex_unlock(&nni_plat_lock); + (void) close(nni_plat_devnull); + pthread_mutexattr_destroy(&nni_mxattr); + pthread_condattr_destroy(&nni_cvattr); + return (NNG_ENOMEM); + } + + // We don't force this, but we want to have it small... we could + // probably get by with even just 8k, but Linux usually wants 16k + // as a minimum. If this fails, its not fatal, just we won't be + // as scalable / thrifty with our use of VM. + (void) pthread_attr_setstacksize(&nni_pthread_attr, 16384); + if (pthread_atfork(NULL, NULL, nni_atfork_child) != 0) { pthread_mutex_unlock(&nni_plat_lock); (void) close(nni_plat_devnull); + pthread_mutexattr_destroy(&nni_mxattr); + pthread_condattr_destroy(&nni_cvattr); + pthread_attr_destroy(&nni_pthread_attr); return (NNG_ENOMEM); } if ((rv = helper()) == 0) { @@ -284,6 +304,7 @@ nni_plat_fini(void) if (nni_plat_inited) { pthread_mutexattr_destroy(&nni_mxattr); pthread_condattr_destroy(&nni_cvattr); + pthread_attr_destroy(&nni_pthread_attr); (void) close(nni_plat_devnull); nni_plat_devnull = -1; nni_plat_inited = 0; -- cgit v1.2.3-70-g09d2