NE_SOCK_INIT(3)
β¨ NE_SOCK_INIT(3) β the neon API reference, bestie edition β¨
okay so this is the neon manual page for ne_sock_init / ne_sock_exit, aka the "wake the library up" and "put the library to bed" duo. section 3, library functions, we love to see it π
πΈ NAME πΈ
ne_sock_init, ne_sock_exit β literally just doing library initialization. that's the whole job. perform library initialization. slay.
π SYNOPSIS π
#include <ne_socket.h>
int ne_sock_init(void);
void ne_sock_exit(void);
no cap, that's the entire API surface. two functions. one gives you an int back, one gives you nothing back. balance β¨
π¦ DESCRIPTION π¦
so here's the vibe: on some platforms and in some configurations, neon might be out here using socket libraries or SSL libraries that need global initialization before you can touch them. like they need to be warmed up first, iykyk. to do that initialization, the ne_sock_init function must be called before any other library functions are used. not optional. must. before any other library functions. periodt.
once you're fully done using neon, ne_sock_exit can be called to perform de-initialization of the socket or SSL libraries, if necessary. (if necessary!! it's conditional, don't come for me.)
and here's the cute part β uses of ne_sock_init and ne_sock_exit are "reference counted". so if N calls to ne_sock_init happen, only the Nth call to ne_sock_exit will have any effect. so you can stack them like little nesting dolls πͺ and only the last one out actually turns off the lights.
ne_sock_init will set the disposition of the SIGPIPE signal to ignored. meanwhile ne_sock_exit makes no change to the SIGPIPE disposition at all. it's giving "not my department" π
π the SSL callback situation (a saga)
both SSL libraries supported by neon β OpenSSL and GnuTLS β require callbacks to be registered to allow thread-safe use of SSL. and these callbacks are stored as global variables, so their state persists for as long as the library in question is loaded into the process. so far so fine, right?
but π if multiple users of the SSL library exist within the process, this can be problematic β especially if one of them is dynamically loaded (and may subsequently be unloaded). that's the messy part. it's giving drama.
so: if neon is configured using the --enable-threadsafe-ssl flag, thread-safe SSL support will be enabled automatically, as covered in the next section. otherwise, it is not safe to use neon with SSL in a multi-threaded process. like genuinely not safe, bestie, be careful. the ne_has_support(3) function can be used to determine whether neon is built to enable thread-safety support in the SSL library. use it. it's right there. π«Ά
π Thread-safe SSL with OpenSSL
neon follows two simple rules when dealing with the OpenSSL locking callbacks, and honestly? iconic of it:
ne_sock_initwill set thread-safety locking callbacks if and only if no locking callbacks are already registered.ne_sock_exitwill unset the thread-safety locking callbacks if and only if the locking callbacks registered are those registered byne_sock_init.
applications and libraries should be able to co-operate to ensure that SSL use is always thread-safe β if similar rules are always followed. teamwork makes the dream work π€
π§ Thread-safe SSL with GnuTLS
okay this one's a little different. the cryptography library used by GnuTLS, libgcrypt, only supports an initialization operation to register thread-safety callbacks. there's no un-register. no take-backs. so:
ne_sock_initwill register the thread-safe locking callbacks on first use.ne_sock_exitcannot unregister them. it simply cannot, don't ask her to.
and because of that, if multiple users of GnuTLS are present within the process, it is unsafe to dynamically unload neon from the process if neon is configured with thread-safe SSL support enabled β since the callbacks would be left pointing at unmapped memory once neon is unloaded. that's the danger zone π don't do it.
β RETURN VALUE β
ne_sock_init returns zero on success, or non-zero on error. that's it, that's the contract.
β οΈ but listen β if an error occurs, no further use of the neon library should be attempted. like at all. put it down. walk away. do not pass go. π
π SEE ALSO π
π COPYRIGHT π
Copyright Β© 2001-2026 Joe Orton
and that's the page, bestie π β brought to you by the neon API reference, dated 03/20/2026, page NE_SOCK_INIT(3), closing out exactly like it opened. go forth and initialize responsibly β¨π
π¦ where this page comes from
- arch rolling: neon 0.37.1-1 Β· LGPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms