blob: 705c95402adffc1ace959b0a178e80a54360cb77 [file] [log] [blame]
<!DOCTYPE html>
<html xmlns="" xml:lang="en" lang="en">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="en-us" http-equiv="Content-Language" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/static/images/favicon.ico" rel="shortcut icon" />
<link href="/static/css/style.css" rel="stylesheet" type="text/css" />
<link href="/static/css/codehilite.css" rel="stylesheet" type="text/css" />
<link href="/static/css/bootstrap.css" media="screen, projection" rel="stylesheet" type="text/css" />
<link href="/static/css/thrift.css" media="screen, projection" rel="stylesheet" type="text/css" />
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap-dropdown.js"></script>
<script src="/static/js/bootstrap-tab.js"></script>
<script src="/static/js/thrift.js"></script>
<title>Apache Thrift - C++ library</title>
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="/">Apache Thrift &trade;</a>
<div class="nav-collapse">
<ul class="nav pull-right">
<li><a href="/download">Download</a></li>
<li><a href="/docs">Documentation</a></li>
<li><a href="/developers">Developers</a></li>
<li><a href="/lib">Libraries</a></li>
<li><a href="/tutorial">Tutorial</a></li>
<li><a href="/test">Test Suite</a></li>
<li><a href="/about">About</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Apache <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="" target="_blank">Apache Home</a></li>
<li><a href="" target="_blank">Apache License v2.0</a></li>
<li><a href="" target="_blank">Donate</a></li>
<li><a href="" target="_blank">Thanks</a></li>
<li><a href="" target="_blank">Security</a></li>
<div class="container">
<h1 id="using-thrift-with-c">Using Thrift with C++</h1>
<p>The Thrift C++ libraries are built using the GNU tools. Follow the instructions
in the top-level</p>
<p>In case you do not want to open another file, do this thrift src:</p>
./configure (--with-boost=/usr/local)
sudo make install
<p>Thrift is divided into two libraries.</p>
<p>libthrift - The core Thrift library contains all the core Thrift code. This requires
openssl, pthreads, and librt.</p>
<p>libthriftnb - This library contains the Thrift nonblocking server, which uses libevent.
To link this library you will also need to link libevent.</p>
<h2 id="linking-against-thrift">Linking Against Thrift</h2>
<p>After you build and install Thrift the libraries are installed to
/usr/local/lib by default. Make sure this is in your LDPATH.</p>
<p>On Linux, the best way to do this is to ensure that /usr/local/lib is in
your /etc/ and then run /sbin/ldconfig.</p>
<p>Depending upon whether you are linking dynamically or statically and how
your build environment it set up, you may need to include additional
libraries when linking against thrift, such as librt and/or libpthread. If
you are using libthriftnb you will also need libevent.</p>
<h2 id="dependencies">Dependencies</h2>
<p>C++11 is required at a minimum. C++03/C++98 are not supported after version 0.12.0.</p>
<p>Boost is required to run the C++ unit tests. It is not necessary to link against
the runtime library.</p>
<p>libevent (for libthriftnb only) - most linux distributions have dev packages for this:</p>
<h1 id="using-thrift-with-c-on-windows">Using Thrift with C++ on Windows</h1>
<p>Both the autoconf and cmake build systems are able to automatically detect many
system configurations without the need to specify library locations, however if
you run into problems or want to redirect thrift to build and link against your
own provided third party libraries:</p>
<p>BOOST_ROOT : For boost, e.g. D:\boost_1_55_0
OPENSSL_ROOT_DIR : For OpenSSL, e.g. D:\OpenSSL-Win32</p>
<p>only required by libthriftnb:</p>
<p>LIBEVENT_ROOT_DIR : For Libevent e.g. D:\libevent-2.0.21-stable</p>
<p>See /3rdparty.user for more details.</p>
<p>The same linking guidelines described above for libthriftnb apply to windows as well.</p>
<h2 id="linking-against-thrift-1">Linking Against Thrift</h2>
<p>You need to link your project that uses thrift against all the thrift
dependencies; in the case of libthrift, openssl, pthreads, and librt and for
libthriftnb, libevent.</p>
<p>In the project properties you must also set HAVE_CONFIG_H as force include
the config header: &#8220;windows/config.h&#8221;</p>
<h2 id="dependencies-1">Dependencies</h2>
<p>libevent (for libthriftnb only)</p>
<h2 id="windows-version-compatibility">Windows version compatibility</h2>
<p>The Thrift library targets Windows 7 or latter versions. The supports for windows XP and Vista are avaiable until 0.12.0.</p>
<h2 id="thrift-and-the-vcpkg-package-manager">Thrift and the VCPKG Package manager</h2>
<p>You can download and install thrift using the
<a href="">vcpkg</a> dependency manager:</p>
<pre><code>git clone
cd vcpkg
./vcpkg integrate install
./vcpkg install thrift
<p>The thrift port in vcpkg is kept up to date by Microsoft team members
and community contributors. The Apache Thrift project is <em>not</em> responsible
for the vcpkg port. Therefore, if the version is out of date, please
<a href="">create an issue or pull request</a>
on the vcpkg repository.</p>
<h2 id="named-pipes">Named Pipes</h2>
<p>Named Pipe transport has been added in the TPipe and TPipeServer classes. This
is currently Windows-only. Named pipe transport for *NIX has not been
implemented. Domain sockets are a better choice for local IPC under non-Windows
OS&#8217;s. *NIX named pipes only support 1:1 client-server connection.</p>
<h1 id="thriftssl">Thrift/SSL</h1>
<h2 id="scope">Scope</h2>
<p>This SSL only supports blocking mode socket I/O. It can only be used with
TSimpleServer, TThreadedServer, and TThreadPoolServer.</p>
<h2 id="implementation">Implementation</h2>
<p>There are two main classes TSSLSocketFactory and TSSLSocket. Instances of
TSSLSocket are always created from TSSLSocketFactory.</p>
<h2 id="how-to-use-ssl-apis">How to use SSL APIs</h2>
<p>See the TestClient.cpp and TestServer.cpp files for examples.</p>
<h3 id="accessmanager-certificate-validation">AccessManager (certificate validation)</h3>
<p>An example of certificate validation can be found in TestServer.cpp.</p>
<p>AccessManager defines a callback interface. It has three callback methods:</p>
<p>(a) Decision verify(const sockaddr_storage&amp; sa);</p>
<p>(b) Decision verify(const string&amp; host, const char* name, int size);</p>
<p>(c) Decision verify(const sockaddr_storage&amp; sa, const char* data, int size);</p>
<p>After SSL handshake completes, additional checks are conducted. Application
is given the chance to decide whether or not to continue the conversation
with the remote. Application is queried through the above three &#8220;verify&#8221;
method. They are called at different points of the verification process.</p>
<p>Decisions can be one of ALLOW, DENY, and SKIP. ALLOW and DENY means the
conversation should be continued or disconnected, respectively. ALLOW and
DENY decision stops the verification process. SKIP means there&#8217;s no decision
based on the given input, continue the verification process.</p>
<p>First, (a) is called with the remote IP. It is called once at the beginning.
&#8220;sa&#8221; is the IP address of the remote peer.</p>
<p>Then, the certificate of remote peer is loaded. SubjectAltName extensions
are extracted and sent to application for verification. When a DNS
subjectAltName field is extracted, (b) is called. When an IP subjectAltName
field is extracted, (c) is called.</p>
<p>The &#8220;host&#8221; in (b) is the value from TSocket::getHost() if this is a client
side socket, or TSocket::getPeerHost() if this is a server side socket. The
reason is client side socket initiates the connection. TSocket::getHost()
is the remote host name. On server side, the remote host name is unknown
unless it&#8217;s retrieved through TSocket::getPeerHost(). Either way, &#8220;host&#8221;
should be the remote host name. Keep in mind, if TSocket::getPeerHost()
failed, it would return the remote host name in numeric format.</p>
<p>If all subjectAltName extensions were &#8220;skipped&#8221;, the common name field would
be checked. It is sent to application through (c), where &#8220;sa&#8221; is the remote
IP address. &#8220;data&#8221; is the IP address extracted from subjectAltName IP
extension, and &#8220;size&#8221; is the length of the extension data.</p>
<p>If any of the above &#8220;verify&#8221; methods returned a decision ALLOW or DENY, the
verification process would be stopped.</p>
<p>If any of the above &#8220;verify&#8221; methods returned SKIP, that decision would be
ignored and the verification process would move on till the last item is
examined. At that point, if there&#8217;s still no decision, the connection is
<p>Thread safety, an access manager should not store state information if it&#8217;s
to be used by many SSL sockets.</p>
<h2 id="sigpipe-signal">SIGPIPE signal</h2>
<p>Applications running OpenSSL over network connections may crash if SIGPIPE
is not ignored. This happens when they receive a connection reset by remote
peer exception, which somehow triggers a SIGPIPE signal. If not handled,
this signal would kill the application.</p>
<h2 id="how-to-run-test-clientserver-in-ssl-mode">How to run test client/server in SSL mode</h2>
<p>The server and client expects the followings from the directory /test/</p>
<p>The file names are hard coded in the source code. You need to create these
certificates before you can run the test code in SSL mode. Make sure at least
one of the followings is included in &#8220;keys/server.crt&#8221;,</p>
<li>subjectAltName, DNS localhost</li>
<li>subjectAltName, IP</li>
<li>common name, localhost</li>
<p>Run within /test/ folder,</p>
<pre><code> ./cpp/TestServer --ssl &amp;
./cpp/TestClient --ssl
<p>If &#8220;-h <host>" is used to run client, the above "localhost" in the above
keys/server.crt has to be replaced with that host name.</host></p>
<h2 id="tsslsocketfactoryrandomize">TSSLSocketFactory::randomize()</h2>
<p>The default implementation of OpenSSLSocketFactory::randomize() simply calls
OpenSSL&#8217;s RAND_poll() when OpenSSL library is first initialized.</p>
<p>The PRNG seed is key to the application security. This method should be
overridden if it&#8217;s not strong enough for you.</p>
<h1 id="deprecations">Deprecations</h1>
<h2 id="section">0.12.0</h2>
<p>Support for C++03/C++98 was deprecated.
Support for Boost at runtime was deprecated.</p>
<h1 id="breaking-changes">Breaking Changes</h1>
<h2 id="section-1">1.0.0</h2>
The classes Monitor and TimerManager now use std::chrono::milliseconds for timeout, the methods and functions involving THRIFT_TIMESPEC and timeval have been removed, the related tests have been modified.</p>
<p>Support for Windows XP/Vista has been dropped.</p>
<p>Support for C++03/C++98 has been dropped. Use version 0.12.0 to support that
language level. As a consequence, boost is no longer required as a runtime
library depenedency, but is is still required to build the runtime library
and to run the unit tests. We will work towards removing boost as a
build dependency for folks who just want to build the runtime and not
run the tests. This means the header thrift/stdcxx.h has been removed and
anything that relied on it has been changed to directly use C++11 concepts.</p>
The classes BoostThreadFactory, PosixThreadFactory, StdThreadFactory, and
PlatformThreadFactory have been removed, and we will use a ThreadFactory
based on C++11 (essentially StdThreadFactory was renamed ThreadFactory).</p>
The CMake build options WITH_SHARED_LIBS and WITH_STATIC_LIBS are deprecated.
The project no longer performs a side-by-side static and shared build; you
tell CMake through BUILD_SHARED_LIBS whether to make shared or static
libraries now. This is CMake standard behavior.</p>
Qt4 support was removed.</p>
Added <code>const</code> specifier to <code>TTransport::getOrigin()</code>. This changes its function signature.
It&#8217;s recommended to add the <code>override</code> specifier in implementations derived from <code>TTransport</code>.</p>
<h2 id="section-2">0.11.0</h2>
<p>Older versions of thrift depended on the &lt;boost/smart_ptr.hpp&gt; classes which
were used in thrift headers to define interfaces. Thrift now detects C++11
at build time and will prefer to use <memory> classes from C++11 instead.
You can force the library to build with boost memory classes by defining the
preprocessor macro `FORCE_BOOST_SMART_PTR`. (THRIFT-2221)</memory></p>
<p>In the pthread mutex implementation, the contention profiling code was enabled
by default in all builds. This changed to be disabled by default. (THRIFT-4151)</p>
<p>In older releases, if a TSSLSocketFactory&#8217;s lifetime was not at least as long
as the TSSLSockets it created, we silently reverted openssl to unsafe multithread behavior
and so the results were undefined. Changes were made in 0.11.0 that cause either an
assertion or a core instead of undefined behavior. The lifetime of a TSSLSocketFactory
<em>must</em> be longer than any TSSLSocket that it creates, otherwise openssl will be cleaned
up too early. If the static boolean is set to disable openssl initialization and
cleanup and leave it up to the consuming application, this requirement is not needed.
<p class="snippet_footer">This page was generated by Apache Thrift's <strong>source tree docs</strong>:
<a href=";a=blob;hb=HEAD;f=lib/cpp/">lib/cpp/</a>
<div class="container">
<footer class="footer">
<div class="row">
<div class="span3">
<ul class="unstyled">
<li><a href="/download">Download</a></li>
<li><a href="/developers">Developers</a></li>
<li><a href="/tutorial">Tutorials</a></li>
<ul class="unstyled">
<li><a href="/sitemap">Sitemap</a></li>
<div class="span3">
<h3>Get Involved</h3>
<ul class="unstyled">
<li><a href="/mailing">Mailing Lists</a></li>
<li><a href="">Issue Tracking</a></li>
<li><a href="/docs/HowToContribute">How To Contribute</a></li>
<div class="span6">
<a href=""><img src="/static/images/feather.svg" onerror="this.src='/static/images/feather.png';this.onerror=null;" /></a>
Copyright &copy; 2023 <a href="">Apache Software Foundation</a>.
Licensed under the <a href="">Apache License v2.0</a>.
Apache, Apache Thrift, and the Apache feather logo are trademarks of The Apache Software Foundation.