Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
c778e70f
Commit
c778e70f
authored
Jul 02, 2018
by
wangxuefeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove thrift marco in user code.
parent
87592e12
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
33 additions
and
37 deletions
+33
-37
CMakeLists.txt
CMakeLists.txt
+15
-2
Makefile
Makefile
+2
-2
thrift.md
docs/cn/thrift.md
+2
-1
thrift.md
docs/en/thrift.md
+2
-1
Makefile
example/thrift_extension_c++/Makefile
+4
-4
thrift_utils.h
src/brpc/details/thrift_utils.h
+0
-3
global.cpp
src/brpc/global.cpp
+8
-5
thrift_protocol.cpp
src/brpc/policy/thrift_protocol.cpp
+0
-3
thrift_protocol.h
src/brpc/policy/thrift_protocol.h
+0
-4
thrift_message.cpp
src/brpc/thrift_message.cpp
+0
-3
thrift_message.h
src/brpc/thrift_message.h
+0
-3
thrift_service.cpp
src/brpc/thrift_service.cpp
+0
-2
thrift_service.h
src/brpc/thrift_service.h
+0
-4
No files found.
CMakeLists.txt
View file @
c778e70f
...
...
@@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 2.8.10)
project
(
brpc C CXX
)
# Enable MACOSX_RPATH. Run "cmake --help-policy CMP0042" for policy details.
cmake_policy
(
SET CMP0042 NEW
)
if
(
POLICY CMP0042
)
cmake_policy
(
SET CMP0042 NEW
)
endif
()
set
(
BRPC_VERSION 0.9.0
)
...
...
@@ -38,7 +40,6 @@ endif()
if
(
BRPC_WITH_THRIFT
)
set
(
THRIFT_CPP_FLAG
"-DENABLE_THRIFT_FRAMED_PROTOCOL"
)
set
(
THRIFT_LIB
"thriftnb"
)
message
(
"Enable thrift framed procotol"
)
endif
()
include
(
GNUInstallDirs
)
...
...
@@ -326,6 +327,17 @@ file(GLOB_RECURSE BVAR_SOURCES "${CMAKE_SOURCE_DIR}/src/bvar/*.cpp")
file
(
GLOB_RECURSE BTHREAD_SOURCES
"
${
CMAKE_SOURCE_DIR
}
/src/bthread/*.cpp"
)
file
(
GLOB_RECURSE JSON2PB_SOURCES
"
${
CMAKE_SOURCE_DIR
}
/src/json2pb/*.cpp"
)
file
(
GLOB_RECURSE BRPC_SOURCES
"
${
CMAKE_SOURCE_DIR
}
/src/brpc/*.cpp"
)
file
(
GLOB_RECURSE THRIFT_SOURCES
"thrift*.cpp"
)
if
(
BRPC_WITH_THRIFT
)
message
(
"brpc compile with thrift proctol"
)
else
()
# Remove thrift sources
foreach
(
v
${
THRIFT_SOURCES
}
)
list
(
REMOVE_ITEM BRPC_SOURCES
${
v
}
)
endforeach
()
set
(
THRIFT_SOURCES
""
)
endif
()
set
(
MCPACK2PB_SOURCES
${
CMAKE_SOURCE_DIR
}
/src/mcpack2pb/field_type.cpp
...
...
@@ -366,6 +378,7 @@ set(SOURCES
${
JSON2PB_SOURCES
}
${
MCPACK2PB_SOURCES
}
${
BRPC_SOURCES
}
${
THRIFT_SOURCES
}
)
add_subdirectory
(
src
)
...
...
Makefile
View file @
c778e70f
...
...
@@ -7,8 +7,8 @@ include config.mk
# 3. Removed -Werror: Not block compilation for non-vital warnings, especially when the
# code is tested on newer systems. If the code is used in production, add -Werror back
CPPFLAGS
+=
-DBTHREAD_USE_FAST_PTHREAD_MUTEX
-D__const__
=
-D_GNU_SOURCE
-DUSE_SYMBOLIZE
-DNO_TCMALLOC
-D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
-D__STDC_CONSTANT_MACROS
-DNDEBUG
-DBRPC_REVISION
=
\"
$(
shell
git rev-parse
--short
HEAD
)
\"
CXXFLAGS
=
$(CPPFLAGS)
-
O2
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-invalid-offsetof
-Wno-unused-parameter
-fno-omit-frame-pointer
-std
=
c++0x
CFLAGS
=
$(CPPFLAGS)
-
O2
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-unused-parameter
-fno-omit-frame-pointer
CXXFLAGS
=
$(CPPFLAGS)
-
g
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-invalid-offsetof
-Wno-unused-parameter
-fno-omit-frame-pointer
-std
=
c++0x
CFLAGS
=
$(CPPFLAGS)
-
g
-pipe
-Wall
-W
-fPIC
-fstrict-aliasing
-Wno-unused-parameter
-fno-omit-frame-pointer
DEBUG_CXXFLAGS
=
$
(
filter-out
-DNDEBUG
,
$(CXXFLAGS)
)
-DUNIT_TEST
-DBVAR_NOT_LINK_DEFAULT_VARIABLES
DEBUG_CFLAGS
=
$
(
filter-out
-DNDEBUG
,
$(CFLAGS)
)
-DUNIT_TEST
HDRPATHS
=
-I
./src
$
(
addprefix
-I
,
$(HDRS)
)
...
...
docs/cn/thrift.md
View file @
c778e70f
...
...
@@ -28,8 +28,9 @@ sudo make install
配置brpc支持thrift协议后make。编译完成后会生成libbrpc.a, 其中包含了支持thrift协议的扩展代码, 像正常使用brpc的代码一样链接即可。
```
bash
sh config_brpc.sh
--headers
=
/usr/include
--libs
=
/usr/lib
--with-thrift
#或者使用cmake
mkdir
build
&&
cd
build
&&
cmake ../
-DBRPC_WITH_THRIFT
=
1
```
注意: 在编译用户代码的时候, 请定义ENABLE_THRIFT_FRAMED_PROTOCOL宏, 否则在include brpc中thrift协议相关头文件后, 实际并不生效
# Client端访问thrift server
基本步骤:
...
...
docs/en/thrift.md
View file @
c778e70f
...
...
@@ -28,8 +28,9 @@ sudo make install
Config brpc with thrift support, then make. The compiled libbrpc.a includes extended code for thrift support and can be linked normally as in other brpc projects.
```
bash
sh config_brpc.sh
--headers
=
/usr/include
--libs
=
/usr/lib
--with-thrift
#or use cmake
mkdir
build
&&
cd
build
&&
cmake ../
-DBRPC_WITH_THRIFT
=
1
```
PS: Please Define ENABLE_THRIFT_FRAMED_PROTOCOL Marco in user code in order to make it work when including thrift utils headers in brpc.
# Client accesses thrift server
Steps:
...
...
example/thrift_extension_c++/Makefile
View file @
c778e70f
...
...
@@ -3,7 +3,7 @@ include $(BRPC_PATH)/config.mk
# Notes on the flags:
# 1. Added -fno-omit-frame-pointer: perf/tcmalloc-profiler use frame pointers by default
# 2. Added -D__const__= : Avoid over-optimizations of TLS variables by GCC>=4.8
CXXFLAGS
=
-std
=
c++0x
-g
-D
ENABLE_THRIFT_FRAMED_PROTOCOL
-D
DEBUG
-D__const__
=
-pipe
-W
-Wall
-Werror
-Wno-unused-parameter
-fPIC
-fno-omit-frame-pointer
CXXFLAGS
=
-std
=
c++0x
-g
-DDEBUG
-D__const__
=
-pipe
-W
-Wall
-Werror
-Wno-unused-parameter
-fPIC
-fno-omit-frame-pointer
HDRS
+=
$(BRPC_PATH)
/output/include
LIBS
+=
$(BRPC_PATH)
/output/lib
HDRPATHS
=
$
(
addprefix
-I
,
$(HDRS)
)
...
...
@@ -11,7 +11,7 @@ LIBPATHS = $(addprefix -L, $(LIBS))
COMMA
=
,
SOPATHS
=
$
(
addprefix
-Wl
$(COMMA)
-rpath
=
,
$(LIBS)
)
STATIC_LINKINGS
+=
-l
brpc
-lthrift
-lgflags
-Wl
,--whole-archive
-Wl
,--no-whole-archive
-levent
STATIC_LINKINGS
+=
-l
thrift
-lgflags
-lbrpc
-levent
-lpthread
-lssl
-lcrypto
-ldl
-lz
-lrt
-lleveldb
CLIENT_SOURCES
=
client.cpp
SERVER_SOURCES
=
server.cpp
...
...
@@ -32,11 +32,11 @@ clean:
echo_client
:
$(PROTO_OBJS) $(CLIENT_OBJS) libechothrift.a
@
echo
"Linking
$@
"
@
$(CXX)
$(LIBPATHS)
$(SOPATHS)
-Xlinker
"-("
$^
-Xlinker
"-)"
$(STATIC_LINKINGS)
$(DYNAMIC_LINKINGS)
-o
$@
@
$(CXX)
$(LIBPATHS)
$(SOPATHS)
-Xlinker
"-("
$^
-Xlinker
"-)"
$(STATIC_LINKINGS)
-o
$@
echo_server
:
$(PROTO_OBJS) $(SERVER_OBJS) libechothrift.a
@
echo
"Linking
$@
"
@
$(CXX)
$(LIBPATHS)
$(SOPATHS)
-Xlinker
"-("
$^
libechothrift.a
-Xlinker
"-)"
$(STATIC_LINKINGS)
$(DYNAMIC_LINKINGS)
-o
$@
@
$(CXX)
$(LIBPATHS)
$(SOPATHS)
-Xlinker
"-("
$^
libechothrift.a
-Xlinker
"-)"
$(STATIC_LINKINGS)
-o
$@
%.o
:
%.cpp libechothrift.a
@
echo
"Compiling
$@
"
...
...
src/brpc/details/thrift_utils.h
View file @
c778e70f
...
...
@@ -14,8 +14,6 @@
// utils for serialize/parse thrift binary message to brpc protobuf obj.
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
#ifndef BRPC_THRIFT_UTILS_H
#define BRPC_THRIFT_UTILS_H
...
...
@@ -120,4 +118,3 @@ bool serialize_iobuf_to_thrift_message(butil::IOBuf& body,
#endif //BRPC_THRIFT_UTILS_H
#endif //ENABLE_THRIFT_FRAMED_PROTOCOL
src/brpc/global.cpp
View file @
c778e70f
...
...
@@ -77,7 +77,10 @@
extern
"C"
{
// defined in gperftools/malloc_extension_c.h
void
BAIDU_WEAK
MallocExtension_ReleaseFreeMemory
(
void
);
void
BAIDU_WEAK
RegisterThriftProtocol
();
// Register Thrift Protocol if thrift was enabled
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
void
RegisterThriftProtocol
();
#endif
}
namespace
brpc
{
...
...
@@ -466,10 +469,10 @@ static void GlobalInitializeOrDieImpl() {
exit
(
1
);
}
// Register Thrift framed protocol if linked
if
(
RegisterThriftProtocol
)
{
RegisterThriftProtocol
();
}
// Use Macro is more straight forward than weak link technology(becasue of static link issue)
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
RegisterThriftProtocol
();
#endif
// Only valid at client side
Protocol
ubrpc_compack_protocol
=
{
...
...
src/brpc/policy/thrift_protocol.cpp
View file @
c778e70f
...
...
@@ -14,8 +14,6 @@
// Authors: wangxuefeng (wangxuefeng@didichuxing.com)
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
#include <google/protobuf/descriptor.h> // MethodDescriptor
#include <google/protobuf/message.h> // Message
#include <gflags/gflags.h>
...
...
@@ -648,4 +646,3 @@ void RegisterThriftProtocol() {
}
}
#endif
src/brpc/policy/thrift_protocol.h
View file @
c778e70f
...
...
@@ -14,8 +14,6 @@
// Authors: wangxuefeng (wangxuefeng@didichuxing.com)
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
#ifndef BRPC_POLICY_THRIFT_PROTOCOL_H
#define BRPC_POLICY_THRIFT_PROTOCOL_H
...
...
@@ -51,6 +49,4 @@ bool VerifyThriftRequest(const InputMessageBase *msg);
}
// namespace policy
}
// namespace brpc
#endif // BRPC_POLICY_THRIFT_PROTOCOL_H
#endif
src/brpc/thrift_message.cpp
View file @
c778e70f
...
...
@@ -14,8 +14,6 @@
// Authors: wangxuefeng (wangxuefeng@didichuxing.com)
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
#define INTERNAL_SUPPRESS_PROTOBUF_FIELD_DEPRECATION
#include "brpc/thrift_message.h"
...
...
@@ -246,4 +244,3 @@ void ThriftFramedMessage::Swap(ThriftFramedMessage* other) {
}
// namespace brpc
#endif
src/brpc/thrift_message.h
View file @
c778e70f
...
...
@@ -14,8 +14,6 @@
// Authors: wangxuefeng (wangxuefeng@didichuxing.com)
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
#ifndef BRPC_THRIFT_MESSAGE_H
#define BRPC_THRIFT_MESSAGE_H
...
...
@@ -167,4 +165,3 @@ private:
#endif // BRPC_THRIFT_MESSAGE_H
#endif //ENABLE_THRIFT_FRAMED_PROTOCOL
src/brpc/thrift_service.cpp
View file @
c778e70f
...
...
@@ -13,7 +13,6 @@
// limitations under the License.
// Authors: wangxuefeng (wangxuefeng@didichuxing.com)
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
#include "butil/class_name.h"
#include "brpc/thrift_service.h"
...
...
@@ -58,4 +57,3 @@ void ThriftService::Expose(const butil::StringPiece& prefix) {
}
// namespace brpc
#endif
src/brpc/thrift_service.h
View file @
c778e70f
...
...
@@ -14,8 +14,6 @@
// Authors: wangxuefeng (wangxuefeng@didichuxing.com)
#ifdef ENABLE_THRIFT_FRAMED_PROTOCOL
#ifndef BRPC_THRIFT_SERVICE_H
#define BRPC_THRIFT_SERVICE_H
...
...
@@ -130,5 +128,3 @@ private:
#endif // BRPC_THRIFT_SERVICE_H
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment