init.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <refentry id="refsockinit">
  2. <refmeta>
  3. <refentrytitle>ne_sock_init</refentrytitle>
  4. <manvolnum>3</manvolnum>
  5. </refmeta>
  6. <refnamediv>
  7. <refname id="ne_sock_init">ne_sock_init</refname>
  8. <refname id="ne_sock_exit">ne_sock_exit</refname>
  9. <refpurpose>perform library initialization</refpurpose>
  10. </refnamediv>
  11. <refsynopsisdiv>
  12. <funcsynopsis>
  13. <funcsynopsisinfo>#include &lt;ne_socket.h&gt;</funcsynopsisinfo>
  14. <funcprototype>
  15. <funcdef>int <function>ne_sock_init</function></funcdef>
  16. <void/>
  17. </funcprototype>
  18. <funcprototype>
  19. <funcdef>void <function>ne_sock_exit</function></funcdef>
  20. <void/>
  21. </funcprototype>
  22. </funcsynopsis>
  23. </refsynopsisdiv>
  24. <refsect1>
  25. <title>Description</title>
  26. <para>In some platforms and configurations, &neon; may be using
  27. some socket or SSL libraries which require global initialization
  28. before use. To perform this initialization, the
  29. <function>ne_sock_init</function> function must be called before
  30. any other library functions are used.</para>
  31. <para>Once all use of &neon; is complete,
  32. <function>ne_sock_exit</function> can be called to perform
  33. de-initialization of socket or SSL libraries, if necessary. Uses
  34. of <function>ne_sock_init</function> and
  35. <function>ne_sock_exit</function> are "reference counted"; if N
  36. calls to <function>ne_sock_init</function> are made, only the Nth
  37. call to <function>ne_sock_exit</function> will have effect.</para>
  38. <para><function>ne_sock_init</function> will set the disposition
  39. of the <literal>SIGPIPE</literal> signal to
  40. <emphasis>ignored</emphasis>. No change is made to the
  41. <literal>SIGPIPE</literal> disposition by
  42. <function>ne_sock_exit</function>.</para>
  43. <para>Both the SSL libraries supported by &neon; &mdash; OpenSSL
  44. and GnuTLS &mdash; require callbacks to be registered to allow
  45. thread-safe use of SSL. These callbacks are stored as global
  46. variables and so their state persists for as long as the library
  47. in question is loaded into the process. If multiple users of the
  48. SSL library exist within the process, this can be problematic,
  49. particularly if one is dynamically loaded (and may subsequently be
  50. unloaded).</para>
  51. <para>If &neon; is configured using the
  52. <literal>--enable-threadsafe-ssl</literal> flag, thread-safe SSL
  53. support will be enabled automatically, as covered in the following
  54. section. Otherwise, it is not safe to use &neon; with SSL in a
  55. multi-threaded process. The <xref linkend="ne_has_support"/>
  56. function can be used to determine whether &neon; is built to
  57. enable thread-safety support in the SSL library.</para>
  58. <refsect2>
  59. <title>Thread-safe SSL with OpenSSL</title>
  60. <para>&neon; follows two simple rules when dealing with the
  61. OpenSSL locking callbacks:
  62. <itemizedlist>
  63. <listitem><simpara><function>ne_sock_init</function> will set
  64. thread-safety locking callbacks if and only if no locking
  65. callbacks are already registered.</simpara></listitem>
  66. <listitem><simpara><function>ne_sock_exit</function> will
  67. unset the thread-safety locking callbacks if and only if the
  68. locking callbacks registered are those registered by
  69. <function>ne_sock_init</function>.</simpara></listitem>
  70. </itemizedlist>
  71. Applications and libraries should be able to co-operate to
  72. ensure that SSL use is always thread-safe if similar rules are
  73. always followed.</para>
  74. </refsect2>
  75. <refsect2>
  76. <title>Thread-safe SSL with GnuTLS</title>
  77. <para>The cryptography library used by GnuTLS, libgcrypt, only
  78. supports an initialization operation to register thread-safety
  79. callbacks. <function>ne_sock_init</function> will register the
  80. thread-safe locking callbacks on first use;
  81. <function>ne_sock_exit</function> cannot unregister them. If
  82. multiple users of GnuTLS are present within the process, it is
  83. unsafe to dynamically unload &neon; from the process if &neon;
  84. is configured with thread-safe SSL support enabled (since the
  85. callbacks would be left pointing at unmapped memory once &neon;
  86. is unloaded).</para>
  87. </refsect2>
  88. </refsect1>
  89. <refsect1>
  90. <title>Return value</title>
  91. <para><function>ne_sock_init</function> returns zero on success,
  92. or non-zero on error. If an error occurs, no further use of the
  93. &neon; library should be attempted.</para>
  94. </refsect1>
  95. <refsect1>
  96. <title>See also</title>
  97. <para><xref linkend="refneon"/>, <xref linkend="reffeat"/></para>
  98. </refsect1>
  99. </refentry>