Skip to content

Commit

Permalink
make config_brpc.sh silent and make thrift_demo runable
Browse files Browse the repository at this point in the history
  • Loading branch information
ZjuYTW committed Aug 26, 2023
1 parent a75ace8 commit 8f08146
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
11 changes: 5 additions & 6 deletions config_brpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,14 @@ if [ $WITH_THRIFT != 0 ]; then
append_to_output "STATIC_LINKINGS+=-lthriftnb"
fi
# get thrift version
thrift_version=$(thrift --version|awk '{print $3}')
IFS='.' read -ra version_parts <<< "$thrift_version"
major=${version_parts[0]}
minor=${version_parts[1]}
thrift_version=$(thrift --version | awk '{print $3}')
major=$(echo "$thrift_version" | awk -F '.' '{print $1}')
minor=$(echo "$thrift_version" | awk -F '.' '{print $2}')
if [ $((major)) -eq 0 -a $((minor)) -lt 11 ]; then
echo "Thrift version is less than 0.11.0"
CPPFLAGS="${CPPFLAGS} -D_THRIFT_VERSION_LOWER_THAN_0_11_0_"
echo "less"
else
echo "Thrift version is equal to or greater than 0.11.0"
echo "greater"
fi
fi

Expand Down
5 changes: 4 additions & 1 deletion example/thrift_extension_c++/native_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
#include <butil/logging.h>

// _THRIFT_STDCXX_H_ is defined by thrift/stdcxx.h which was added since thrift 0.11.0
// but deprecated after 0.13.0
#ifndef THRIFT_STDCXX
#if defined(_THRIFT_STDCXX_H_)
# define THRIFT_STDCXX apache::thrift::stdcxx
#else
#elif defined(_THRIFT_VERSION_LOWER_THAN_0_11_0_)
# define THRIFT_STDCXX boost
# include <boost/make_shared.hpp>
#else
# define THRIFT_STDCXX std
#endif
#endif

Expand Down
21 changes: 17 additions & 4 deletions example/thrift_extension_c++/native_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TTransportUtils.h>
#include <thrift/server/TNonblockingServer.h>
#include <thrift/concurrency/PosixThreadFactory.h>

// _THRIFT_STDCXX_H_ is defined by thrift/stdcxx.h which was added since thrift 0.11.0
// but deprecated after 0.13.0, PosixThreadFactory was also deprecated in 0.13.0
#include <thrift/TProcessor.h> // to include stdcxx.h if present
#ifndef THRIFT_STDCXX
#if defined(_THRIFT_STDCXX_H_)
# define THRIFT_STDCXX apache::thrift::stdcxx
#include <thrift/transport/TNonblockingServerSocket.h>
#else
#include <thrift/concurrency/PosixThreadFactory.h>
#elif defined(_THRIFT_VERSION_LOWER_THAN_0_11_0_)
# define THRIFT_STDCXX boost
# include <boost/make_shared.hpp>
#include <boost/make_shared.hpp>
#include <thrift/concurrency/PosixThreadFactory.h>
#else
# define THRIFT_STDCXX std
#include <thrift/concurrency/ThreadFactory.h>
#include <thrift/transport/TNonblockingServerSocket.h>
#endif
#endif

Expand All @@ -61,10 +67,17 @@ int main(int argc, char *argv[]) {
google::ParseCommandLineFlags(&argc, &argv, true);

THRIFT_STDCXX::shared_ptr<EchoServiceHandler> handler(new EchoServiceHandler());
#if THRIFT_STDCXX != std
// For thrift version less than 0.13.0
THRIFT_STDCXX::shared_ptr<apache::thrift::concurrency::PosixThreadFactory> thread_factory(
new apache::thrift::concurrency::PosixThreadFactory(
apache::thrift::concurrency::PosixThreadFactory::ROUND_ROBIN,
apache::thrift::concurrency::PosixThreadFactory::NORMAL, 1, false));
#else
// For thrift version greater equal than 0.13.0
THRIFT_STDCXX::shared_ptr<apache::thrift::concurrency::ThreadFactory> thread_factory(
new apache::thrift::concurrency::ThreadFactory(false));
#endif

THRIFT_STDCXX::shared_ptr<apache::thrift::server::TProcessor> processor(
new example::EchoServiceProcessor(handler));
Expand All @@ -79,7 +92,7 @@ int main(int argc, char *argv[]) {

thread_mgr->start();

#if defined(_THRIFT_STDCXX_H_)
#if defined(_THRIFT_STDCXX_H_) || !defined (_THRIFT_VERSION_LOWER_THAN_0_11_0_)
THRIFT_STDCXX::shared_ptr<apache::thrift::transport::TNonblockingServerSocket> server_transport =
THRIFT_STDCXX::make_shared<apache::thrift::transport::TNonblockingServerSocket>(FLAGS_port);

Expand Down

0 comments on commit 8f08146

Please sign in to comment.