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
59548597
Commit
59548597
authored
Jul 17, 2018
by
Ge Jun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a proxy example in example/thrift_extension_c++
parent
f364cd37
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
13 deletions
+23
-13
Makefile
example/thrift_extension_c++/Makefile
+10
-4
client.cpp
example/thrift_extension_c++/client.cpp
+3
-2
echo.thrift
example/thrift_extension_c++/echo.thrift
+6
-2
native_client.cpp
example/thrift_extension_c++/native_client.cpp
+3
-3
server.cpp
example/thrift_extension_c++/server.cpp
+1
-1
thrift_protocol.cpp
src/brpc/policy/thrift_protocol.cpp
+0
-1
No files found.
example/thrift_extension_c++/Makefile
View file @
59548597
...
...
@@ -15,20 +15,22 @@ STATIC_LINKINGS += -lthrift -lgflags -lbrpc -levent
CLIENT_SOURCES
=
client.cpp
SERVER_SOURCES
=
server.cpp
SERVER2_SOURCES
=
server2.cpp
PROTOS
=
$
(
wildcard
*
.proto
)
PROTO_OBJS
=
$
(
PROTOS:.proto
=
.pb.o
)
PROTO_GENS
=
$
(
PROTOS:.proto
=
.pb.h
)
$
(
PROTOS:.proto
=
.pb.cc
)
CLIENT_OBJS
=
$
(
addsuffix .o,
$
(
basename
$(CLIENT_SOURCES)
))
SERVER_OBJS
=
$
(
addsuffix .o,
$
(
basename
$(SERVER_SOURCES)
))
CLIENT_OBJS
=
$
(
addsuffix .o,
$
(
basename
$(CLIENT_SOURCES)
))
SERVER_OBJS
=
$
(
addsuffix .o,
$
(
basename
$(SERVER_SOURCES)
))
SERVER2_OBJS
=
$
(
addsuffix .o,
$
(
basename
$(SERVER2_SOURCES)
))
.PHONY
:
all
all
:
echo_client echo_server native_server native_client libechothrift.a client.o server.o
all
:
echo_client echo_server
echo_server2
native_server native_client libechothrift.a client.o server.o
.PHONY
:
clean
clean
:
@
echo
"Cleaning"
@
rm
-rf
echo_client echo_server
$(PROTO_GENS)
$(PROTO_OBJS)
$(CLIENT_OBJS)
$(SERVER
_OBJS)
native_server native_client EchoService.o echo_types.o libechothrift.a gen-cpp gen-py
@
rm
-rf
echo_client echo_server
echo_server2
$(PROTO_GENS)
$(PROTO_OBJS)
$(CLIENT_OBJS)
$(SERVER_OBJS)
$(SERVER2
_OBJS)
native_server native_client EchoService.o echo_types.o libechothrift.a gen-cpp gen-py
echo_client
:
$(PROTO_OBJS) $(CLIENT_OBJS) libechothrift.a
@
echo
"Linking
$@
"
...
...
@@ -38,6 +40,10 @@ echo_server:$(PROTO_OBJS) $(SERVER_OBJS) libechothrift.a
@
echo
"Linking
$@
"
@
$(CXX)
$(LIBPATHS)
$(SOPATHS)
-Xlinker
"-("
$^
libechothrift.a
-Xlinker
"-)"
$(STATIC_LINKINGS)
$(DYNAMIC_LINKINGS)
-o
$@
echo_server2
:
$(PROTO_OBJS) $(SERVER2_OBJS) libechothrift.a
@
echo
"Linking
$@
"
@
$(CXX)
$(LIBPATHS)
$(SOPATHS)
-Xlinker
"-("
$^
libechothrift.a
-Xlinker
"-)"
$(STATIC_LINKINGS)
$(DYNAMIC_LINKINGS)
-o
$@
%.o
:
%.cpp libechothrift.a
@
echo
"Compiling
$@
"
@
$(CXX)
-c
$(HDRPATHS)
$(CXXFLAGS)
$<
-o
$@
...
...
example/thrift_extension_c++/client.cpp
View file @
59548597
...
...
@@ -62,7 +62,8 @@ int main(int argc, char* argv[]) {
example
::
EchoRequest
req
;
example
::
EchoResponse
res
;
req
.
data
=
"hello"
;
req
.
__set_data
(
"hello"
);
req
.
__set_need_by_proxy
(
10
);
stub
.
CallMethod
(
"Echo"
,
&
cntl
,
&
req
,
&
res
,
NULL
);
...
...
@@ -71,7 +72,7 @@ int main(int argc, char* argv[]) {
sleep
(
1
);
// Remove this sleep in production code.
}
else
{
g_latency_recorder
<<
cntl
.
latency_us
();
LOG
(
INFO
)
<<
"Thrift Response: "
<<
res
.
data
;
LOG
(
INFO
)
<<
"Thrift Response: "
<<
res
;
}
LOG_EVERY_SECOND
(
INFO
)
...
...
example/thrift_extension_c++/echo.thrift
View file @
59548597
...
...
@@ -2,8 +2,12 @@
namespace cpp example
struct EchoRequest {
1: required string data;
2: required i32 s;
1: optional string data;
2: optional i32 need_by_proxy;
}
struct ProxyRequest {
2: optional i32 need_by_proxy;
}
struct EchoResponse {
...
...
example/thrift_extension_c++/native_client.cpp
View file @
59548597
...
...
@@ -51,15 +51,15 @@ int main(int argc, char **argv) {
transport
->
open
();
example
::
EchoRequest
req
;
req
.
data
=
"hello"
;
req
.
__set_data
(
"hello"
);
req
.
__set_need_by_proxy
(
10
);
example
::
EchoResponse
res
;
while
(
1
)
{
try
{
client
.
Echo
(
res
,
req
);
LOG
(
INFO
)
<<
"Req: "
<<
req
.
data
<<
" Res: "
<<
res
.
data
;
LOG
(
INFO
)
<<
"Req="
<<
req
<<
" Res="
<<
res
;
}
catch
(
std
::
exception
&
e
)
{
LOG
(
ERROR
)
<<
"Fail to rpc, "
<<
e
.
what
();
}
...
...
example/thrift_extension_c++/server.cpp
View file @
59548597
...
...
@@ -51,7 +51,7 @@ public:
// to process the request asynchronously, pass done_guard.release().
brpc
::
ClosureGuard
done_guard
(
done
);
res
->
data
=
req
->
data
+
" (
processed
)"
;
res
->
data
=
req
->
data
+
" (
Echo
)"
;
}
};
...
...
src/brpc/policy/thrift_protocol.cpp
View file @
59548597
...
...
@@ -351,7 +351,6 @@ void ThriftClosure::DoRun() {
ParseResult
ParseThriftMessage
(
butil
::
IOBuf
*
source
,
Socket
*
,
bool
/*read_eof*/
,
const
void
*
/*arg*/
)
{
char
header_buf
[
sizeof
(
thrift_head_t
)
+
4
];
const
size_t
n
=
source
->
copy_to
(
header_buf
,
sizeof
(
header_buf
));
if
(
n
<
sizeof
(
header_buf
))
{
...
...
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