/usr/share/doc/libssh-doc/html/libssh_tutor_threads.html is in libssh-doc 0.6.1-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>libssh: Chapter 8: Threads with libssh</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">libssh
 <span id="projectnumber">0.6.1</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">index</a></li><li class="navelem"><a class="el" href="libssh_tutorial.html">The Tutorial</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Chapter 8: Threads with libssh </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="threads_with_libssh"></a>
How to use libssh with threads</h1>
<p>libssh may be used in multithreaded applications, but under several conditions :</p>
<ul>
<li>Threading must be initialized during the initialization of libssh. This initialization must be done outside of any threading context.</li>
<li>If pthreads is being used by your application (or your framework's backend), you must link with libssh_threads dynamic library and initialize threading with the ssh_threads_pthreads threading object.</li>
<li>If an other threading library is being used by your application, you must implement all the methods of the ssh_threads_callbacks_struct structure and initialize libssh with it.</li>
<li>At all times, you may use different sessions inside threads, make parallel connections, read/write on different sessions and so on. You <em>cannot</em> use a single session (or channels for a single session) in several threads at the same time. This will most likely lead to internal state corruption. This limitation is being worked out and will maybe disappear later.</li>
</ul>
<h2><a class="anchor" id="threads_init"></a>
Initialization of threads</h2>
<p>To initialize threading, you must first select the threading model you want to use, using <a class="el" href="group__libssh__threads.html#gaf473af3fbae6f1bb0e249fd1d079ff68" title="Set the thread callbacks structure. ">ssh_threads_set_callbacks()</a>, then call <a class="el" href="group__libssh.html#ga3ebf8d6920e563f3b032e3cd5277598e" title="Initialize global cryptographic data structures. ">ssh_init()</a>.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include <libssh/callbacks.h></span></div>
<div class="line">...</div>
<div class="line">ssh_threads_set_callbacks(<a class="code" href="group__libssh__threads.html#gaed3006dbae78414fa3b82c8d9af69a88">ssh_threads_get_noop</a>());</div>
<div class="line"><a class="code" href="group__libssh.html#ga3ebf8d6920e563f3b032e3cd5277598e">ssh_init</a>();</div>
</div><!-- fragment --><p>ssh_threads_noop is the threading structure that does nothing. It's the threading callbacks being used by default when you're not using threading.</p>
<h2><a class="anchor" id="threads_pthread"></a>
Using libpthread with libssh</h2>
<p>If your application is using libpthread, you may simply use the libpthread threading backend:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include <libssh/callbacks.h></span></div>
<div class="line">...</div>
<div class="line">ssh_threads_set_callbacks(ssh_threads_get_pthread());</div>
<div class="line"><a class="code" href="group__libssh.html#ga3ebf8d6920e563f3b032e3cd5277598e">ssh_init</a>();</div>
</div><!-- fragment --><p>However, you must be sure to link with the library ssh_threads. If you're using gcc, you must use the commandline </p>
<div class="fragment"><div class="line">gcc -o output input.c -lssh -lssh_threads</div>
</div><!-- fragment --><h2><a class="anchor" id="threads_other"></a>
Using another threading library</h2>
<p>You must find your way in the ssh_threads_callbacks_struct structure. You must implement the following methods :</p>
<ul>
<li>mutex_lock</li>
<li>mutex_unlock</li>
<li>mutex_init</li>
<li>mutex_destroy</li>
<li>thread_id</li>
</ul>
<p>libgcrypt 1.6 and bigger backend does not support custom callback. Using anything else than pthreads (ssh_threads_get_pthread()) here will fail. Good luck ! </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.6
</small></address>
</body>
</html>
|