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
525cbd48
Commit
525cbd48
authored
Nov 11, 2017
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove most noflush from examples
parent
4f1adbea
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
41 additions
and
127 deletions
+41
-127
client.cpp
example/asynchronous_echo_c++/client.cpp
+4
-10
server.cpp
example/asynchronous_echo_c++/server.cpp
+3
-12
server.cpp
example/backup_request_c++/server.cpp
+0
-3
server.cpp
example/cancel_c++/server.cpp
+3
-11
client.cpp
example/echo_c++/client.cpp
+5
-11
server.cpp
example/echo_c++/server.cpp
+3
-11
client.cpp
example/echo_c++_hulu_pbrpc/client.cpp
+7
-15
server.cpp
example/echo_c++_hulu_pbrpc/server.cpp
+5
-13
server.cpp
example/echo_c++_sofa_pbrpc/server.cpp
+2
-32
client.cpp
example/echo_c++_ubrpc_compack/client.cpp
+6
-6
server.cpp
example/streaming_echo_c++/server.cpp
+3
-3
No files found.
example/asynchronous_echo_c++/client.cpp
View file @
525cbd48
...
@@ -39,16 +39,10 @@ void HandleEchoResponse(
...
@@ -39,16 +39,10 @@ void HandleEchoResponse(
LOG
(
WARNING
)
<<
"Fail to send EchoRequest, "
<<
cntl
->
ErrorText
();
LOG
(
WARNING
)
<<
"Fail to send EchoRequest, "
<<
cntl
->
ErrorText
();
return
;
return
;
}
}
if
(
cntl
->
response_attachment
().
empty
())
{
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
->
remote_side
()
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
->
remote_side
()
<<
": "
<<
response
->
message
()
<<
" (attached="
<<
": "
<<
response
->
message
()
<<
cntl
->
response_attachment
()
<<
")"
<<
" latency="
<<
cntl
->
latency_us
()
<<
"us"
;
<<
" latency="
<<
cntl
->
latency_us
()
<<
"us"
;
}
else
{
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
->
remote_side
()
<<
": "
<<
response
->
message
()
<<
" (attached="
<<
cntl
->
response_attachment
()
<<
")"
<<
" latency="
<<
cntl
->
latency_us
()
<<
"us"
;
}
}
}
...
...
example/asynchronous_echo_c++/server.cpp
View file @
525cbd48
...
@@ -45,19 +45,10 @@ public:
...
@@ -45,19 +45,10 @@ public:
// The purpose of following logs is to help you to understand
// The purpose of following logs is to help you to understand
// how clients interact with servers more intuitively. You should
// how clients interact with servers more intuitively. You should
// remove these logs in performance-sensitive servers.
// remove these logs in performance-sensitive servers.
// You should also noticed that these logs are different from what
// we wrote in other projects: they use << instead of printf-style
// functions. But don't worry, these logs are fully compatible with
// comlog. You can mix them with comlog or ullog functions freely.
// The noflush prevents the log from being flushed immedidately.
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
noflush
;
<<
"] from "
<<
cntl
->
remote_side
()
LOG
(
INFO
)
<<
": "
<<
request
->
message
()
<<
noflush
;
<<
": "
<<
request
->
message
()
if
(
!
cntl
->
request_attachment
().
empty
())
{
<<
" (attached="
<<
cntl
->
request_attachment
()
<<
")"
;
LOG
(
INFO
)
<<
" (attached="
<<
cntl
->
request_attachment
()
<<
")"
<<
noflush
;
}
LOG
(
INFO
);
// Fill response.
// Fill response.
response
->
set_message
(
request
->
message
());
response
->
set_message
(
request
->
message
());
...
...
example/backup_request_c++/server.cpp
View file @
525cbd48
...
@@ -50,9 +50,6 @@ public:
...
@@ -50,9 +50,6 @@ public:
// The purpose of following logs is to help you to understand
// The purpose of following logs is to help you to understand
// how clients interact with servers more intuitively. You should
// how clients interact with servers more intuitively. You should
// remove these logs in performance-sensitive servers.
// remove these logs in performance-sensitive servers.
// You should also noticed that these logs are different from what
// we wrote in other projects: they use << instead of printf-style
// functions.
// The noflush prevents the log from being flushed immediately.
// The noflush prevents the log from being flushed immediately.
LOG
(
INFO
)
<<
"Received request[index="
<<
request
->
index
()
LOG
(
INFO
)
<<
"Received request[index="
<<
request
->
index
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
"] from "
<<
cntl
->
remote_side
()
...
...
example/cancel_c++/server.cpp
View file @
525cbd48
...
@@ -48,19 +48,11 @@ public:
...
@@ -48,19 +48,11 @@ public:
// The purpose of following logs is to help you to understand
// The purpose of following logs is to help you to understand
// how clients interact with servers more intuitively. You should
// how clients interact with servers more intuitively. You should
// remove these logs in performance-sensitive servers.
// remove these logs in performance-sensitive servers.
// You should also noticed that these logs are different from what
// we wrote in other projects: they use << instead of printf-style
// functions. But don't worry, these logs are fully compatible with
// comlog. You can mix them with comlog or ullog functions freely.
// The noflush prevents the log from being flushed immediately.
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
" to "
<<
cntl
->
local_side
()
<<
noflush
;
<<
" to "
<<
cntl
->
local_side
()
LOG
(
INFO
)
<<
": "
<<
request
->
message
()
<<
noflush
;
<<
": "
<<
request
->
message
()
if
(
!
cntl
->
request_attachment
().
empty
())
{
<<
" (attached="
<<
cntl
->
request_attachment
()
<<
")"
;
LOG
(
INFO
)
<<
" (attached="
<<
cntl
->
request_attachment
()
<<
")"
<<
noflush
;
}
LOG
(
INFO
);
// Fill response.
// Fill response.
response
->
set_message
(
request
->
message
());
response
->
set_message
(
request
->
message
());
...
...
example/echo_c++/client.cpp
View file @
525cbd48
...
@@ -77,17 +77,11 @@ int main(int argc, char* argv[]) {
...
@@ -77,17 +77,11 @@ int main(int argc, char* argv[]) {
// the response comes back or error occurs(including timedout).
// the response comes back or error occurs(including timedout).
stub
.
Echo
(
&
cntl
,
&
request
,
&
response
,
NULL
);
stub
.
Echo
(
&
cntl
,
&
request
,
&
response
,
NULL
);
if
(
!
cntl
.
Failed
())
{
if
(
!
cntl
.
Failed
())
{
if
(
cntl
.
response_attachment
().
empty
())
{
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
.
remote_side
()
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
.
remote_side
()
<<
" to "
<<
cntl
.
local_side
()
<<
": "
<<
response
.
message
()
<<
": "
<<
response
.
message
()
<<
" (attached="
<<
" latency="
<<
cntl
.
latency_us
()
<<
"us"
;
<<
cntl
.
response_attachment
()
<<
")"
}
else
{
<<
" latency="
<<
cntl
.
latency_us
()
<<
"us"
;
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
.
remote_side
()
<<
" to "
<<
cntl
.
local_side
()
<<
": "
<<
response
.
message
()
<<
" (attached="
<<
cntl
.
response_attachment
()
<<
")"
<<
" latency="
<<
cntl
.
latency_us
()
<<
"us"
;
}
}
else
{
}
else
{
LOG
(
WARNING
)
<<
cntl
.
ErrorText
();
LOG
(
WARNING
)
<<
cntl
.
ErrorText
();
}
}
...
...
example/echo_c++/server.cpp
View file @
525cbd48
...
@@ -48,19 +48,11 @@ public:
...
@@ -48,19 +48,11 @@ public:
// The purpose of following logs is to help you to understand
// The purpose of following logs is to help you to understand
// how clients interact with servers more intuitively. You should
// how clients interact with servers more intuitively. You should
// remove these logs in performance-sensitive servers.
// remove these logs in performance-sensitive servers.
// You should also noticed that these logs are different from what
// we wrote in other projects: they use << instead of printf-style
// functions. But don't worry, these logs are fully compatible with
// comlog. You can mix them with comlog or ullog functions freely.
// The noflush prevents the log from being flushed immediately.
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
" to "
<<
cntl
->
local_side
()
<<
noflush
;
<<
" to "
<<
cntl
->
local_side
()
LOG
(
INFO
)
<<
": "
<<
request
->
message
()
<<
noflush
;
<<
": "
<<
request
->
message
()
if
(
!
cntl
->
request_attachment
().
empty
())
{
<<
" (attached="
<<
cntl
->
request_attachment
()
<<
")"
;
LOG
(
INFO
)
<<
" (attached="
<<
cntl
->
request_attachment
()
<<
")"
<<
noflush
;
}
LOG
(
INFO
);
// Fill response.
// Fill response.
response
->
set_message
(
request
->
message
());
response
->
set_message
(
request
->
message
());
...
...
example/echo_c++_hulu_pbrpc/client.cpp
View file @
525cbd48
...
@@ -72,21 +72,13 @@ int main(int argc, char* argv[]) {
...
@@ -72,21 +72,13 @@ int main(int argc, char* argv[]) {
// the response comes back or error occurs(including timedout).
// the response comes back or error occurs(including timedout).
stub
.
Echo
(
&
cntl
,
&
request
,
&
response
,
NULL
);
stub
.
Echo
(
&
cntl
,
&
request
,
&
response
,
NULL
);
if
(
!
cntl
.
Failed
())
{
if
(
!
cntl
.
Failed
())
{
if
(
cntl
.
response_attachment
().
empty
())
{
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
.
remote_side
()
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
.
remote_side
()
<<
" to "
<<
cntl
.
local_side
()
<<
": "
<<
response
.
message
()
<<
": "
<<
response
.
message
()
<<
" (attached="
<<
" response_source_addr="
<<
cntl
.
response_source_addr
()
<<
cntl
.
response_attachment
()
<<
")"
<<
" response_user_data=
\"
"
<<
cntl
.
response_user_data
()
<<
" response_source_addr="
<<
cntl
.
response_source_addr
()
<<
" latency="
<<
cntl
.
latency_us
()
<<
"us"
;
<<
" response_user_data=
\"
"
<<
cntl
.
response_user_data
()
}
else
{
<<
"
\"
latency="
<<
cntl
.
latency_us
()
<<
"us"
;
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
.
remote_side
()
<<
" to "
<<
cntl
.
local_side
()
<<
": "
<<
response
.
message
()
<<
" (attached="
<<
cntl
.
response_attachment
()
<<
")"
<<
" response_source_addr="
<<
cntl
.
response_source_addr
()
<<
" response_user_data=
\"
"
<<
cntl
.
response_user_data
()
<<
"
\"
latency="
<<
cntl
.
latency_us
()
<<
"us"
;
}
}
else
{
}
else
{
LOG
(
WARNING
)
<<
cntl
.
ErrorText
();
LOG
(
WARNING
)
<<
cntl
.
ErrorText
();
}
}
...
...
example/echo_c++_hulu_pbrpc/server.cpp
View file @
525cbd48
...
@@ -49,27 +49,19 @@ public:
...
@@ -49,27 +49,19 @@ public:
// The purpose of following logs is to help you to understand
// The purpose of following logs is to help you to understand
// how clients interact with servers more intuitively. You should
// how clients interact with servers more intuitively. You should
// remove these logs in performance-sensitive servers.
// remove these logs in performance-sensitive servers.
// You should also noticed that these logs are different from what
// we wrote in other projects: they use << instead of printf-style
// functions. But don't worry, these logs are fully compatible with
// comlog. You can mix them with comlog or ullog functions freely.
// The noflush prevents the log from being flushed immediately.
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
" to "
<<
cntl
->
local_side
()
<<
noflush
;
<<
" to "
<<
cntl
->
local_side
()
<<
": "
<<
request
->
message
()
<<
" (attached="
<<
cntl
->
request_attachment
()
<<
")"
;
brpc
::
policy
::
HuluController
*
hulu_controller
brpc
::
policy
::
HuluController
*
hulu_controller
=
dynamic_cast
<
brpc
::
policy
::
HuluController
*>
(
cntl
);
=
dynamic_cast
<
brpc
::
policy
::
HuluController
*>
(
cntl
);
if
(
hulu_controller
)
{
if
(
hulu_controller
)
{
LOG
(
INFO
)
<<
"
"
<<
"
source_addr="
LOG
(
INFO
)
<<
"source_addr="
<<
hulu_controller
->
request_source_addr
()
<<
hulu_controller
->
request_source_addr
()
<<
" user_data=
\"
"
<<
hulu_controller
->
request_user_data
()
<<
" user_data=
\"
"
<<
hulu_controller
->
request_user_data
()
<<
'\"'
<<
noflush
;
<<
'\"'
;
}
}
LOG
(
INFO
)
<<
": "
<<
request
->
message
()
<<
noflush
;
if
(
!
cntl
->
request_attachment
().
empty
())
{
LOG
(
INFO
)
<<
" (attached="
<<
cntl
->
request_attachment
()
<<
")"
<<
noflush
;
}
LOG
(
INFO
);
// Fill response.
// Fill response.
response
->
set_message
(
request
->
message
());
response
->
set_message
(
request
->
message
());
...
...
example/echo_c++_sofa_pbrpc/server.cpp
View file @
525cbd48
...
@@ -17,10 +17,8 @@
...
@@ -17,10 +17,8 @@
#include <gflags/gflags.h>
#include <gflags/gflags.h>
#include <butil/logging.h>
#include <butil/logging.h>
#include <brpc/server.h>
#include <brpc/server.h>
#include <brpc/policy/hulu_pbrpc_controller.h>
#include "echo.pb.h"
#include "echo.pb.h"
DEFINE_bool
(
echo_attachment
,
true
,
"Echo attachment as well"
);
DEFINE_int32
(
port
,
8000
,
"TCP Port of this server"
);
DEFINE_int32
(
port
,
8000
,
"TCP Port of this server"
);
DEFINE_int32
(
idle_timeout_s
,
-
1
,
"Connection will be closed if there is no "
DEFINE_int32
(
idle_timeout_s
,
-
1
,
"Connection will be closed if there is no "
"read/write operations during the last `idle_timeout_s'"
);
"read/write operations during the last `idle_timeout_s'"
);
...
@@ -49,27 +47,10 @@ public:
...
@@ -49,27 +47,10 @@ public:
// The purpose of following logs is to help you to understand
// The purpose of following logs is to help you to understand
// how clients interact with servers more intuitively. You should
// how clients interact with servers more intuitively. You should
// remove these logs in performance-sensitive servers.
// remove these logs in performance-sensitive servers.
// You should also noticed that these logs are different from what
// we wrote in other projects: they use << instead of printf-style
// functions. But don't worry, these logs are fully compatible with
// comlog. You can mix them with comlog or ullog functions freely.
// The noflush prevents the log from being flushed immediately.
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
LOG
(
INFO
)
<<
"Received request[log_id="
<<
cntl
->
log_id
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
"] from "
<<
cntl
->
remote_side
()
<<
" to "
<<
cntl
->
local_side
()
<<
noflush
;
<<
" to "
<<
cntl
->
local_side
()
brpc
::
policy
::
HuluController
*
hulu_controller
<<
": "
<<
request
->
message
();
=
dynamic_cast
<
brpc
::
policy
::
HuluController
*>
(
cntl
);
if
(
hulu_controller
)
{
LOG
(
INFO
)
<<
" "
<<
" source_addr="
<<
hulu_controller
->
request_source_addr
()
<<
" user_data=
\"
"
<<
hulu_controller
->
request_user_data
()
<<
'\"'
<<
noflush
;
}
LOG
(
INFO
)
<<
": "
<<
request
->
message
()
<<
noflush
;
if
(
!
cntl
->
request_attachment
().
empty
())
{
LOG
(
INFO
)
<<
" (attached="
<<
cntl
->
request_attachment
()
<<
")"
<<
noflush
;
}
LOG
(
INFO
);
// Fill response.
// Fill response.
response
->
set_message
(
request
->
message
());
response
->
set_message
(
request
->
message
());
...
@@ -77,17 +58,6 @@ public:
...
@@ -77,17 +58,6 @@ public:
// You can compress the response by setting Controller, but be aware
// You can compress the response by setting Controller, but be aware
// that compression may be costly, evaluate before turning on.
// that compression may be costly, evaluate before turning on.
// cntl->set_response_compress_type(brpc::COMPRESS_TYPE_GZIP);
// cntl->set_response_compress_type(brpc::COMPRESS_TYPE_GZIP);
if
(
FLAGS_echo_attachment
)
{
// Set attachment which is wired to network directly instead of
// being serialized into protobuf messages.
cntl
->
response_attachment
().
append
(
cntl
->
request_attachment
());
}
if
(
hulu_controller
)
{
hulu_controller
->
set_response_source_addr
(
hulu_controller
->
request_source_addr
()
+
1
);
hulu_controller
->
set_response_user_data
(
"server user data"
);
}
}
}
};
};
}
// namespace example
}
// namespace example
...
...
example/echo_c++_ubrpc_compack/client.cpp
View file @
525cbd48
...
@@ -108,17 +108,17 @@ int main(int argc, char* argv[]) {
...
@@ -108,17 +108,17 @@ int main(int argc, char* argv[]) {
stub
.
EchoWithMultiArgs
(
&
cntl
,
&
multi_requests
,
&
multi_responses
,
NULL
);
stub
.
EchoWithMultiArgs
(
&
cntl
,
&
multi_requests
,
&
multi_responses
,
NULL
);
}
}
if
(
!
cntl
.
Failed
())
{
if
(
!
cntl
.
Failed
())
{
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
.
remote_side
()
<<
": "
<<
noflush
;
if
(
!
FLAGS_multi_args
)
{
if
(
!
FLAGS_multi_args
)
{
LOG
(
INFO
)
<<
response
.
message
()
<<
noflush
;
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
.
remote_side
()
<<
": "
<<
response
.
message
()
<<
" latency="
<<
cntl
.
latency_us
()
<<
"us"
;
}
else
{
}
else
{
LOG
(
INFO
)
<<
"res1="
<<
multi_responses
.
res1
().
message
()
LOG
(
INFO
)
<<
"Received response from "
<<
cntl
.
remote_side
()
<<
": res1="
<<
multi_responses
.
res1
().
message
()
<<
" res2="
<<
multi_responses
.
res2
().
message
()
<<
" res2="
<<
multi_responses
.
res2
().
message
()
<<
" result="
<<
cntl
.
idl_result
()
<<
" result="
<<
cntl
.
idl_result
()
<<
noflush
;
<<
" latency="
<<
cntl
.
latency_us
()
<<
"us"
;
}
}
LOG
(
INFO
)
<<
" latency="
<<
cntl
.
latency_us
()
<<
"us"
;
}
else
{
}
else
{
LOG
(
ERROR
)
<<
"Fail to send request, "
<<
cntl
.
ErrorText
();
LOG
(
ERROR
)
<<
"Fail to send request, "
<<
cntl
.
ErrorText
();
}
}
...
...
example/streaming_echo_c++/server.cpp
View file @
525cbd48
...
@@ -32,11 +32,11 @@ public:
...
@@ -32,11 +32,11 @@ public:
virtual
int
on_received_messages
(
brpc
::
StreamId
id
,
virtual
int
on_received_messages
(
brpc
::
StreamId
id
,
butil
::
IOBuf
*
const
messages
[],
butil
::
IOBuf
*
const
messages
[],
size_t
size
)
{
size_t
size
)
{
LOG
(
INFO
)
<<
"Received from Stream="
<<
id
<<
": "
<<
noflush
;
std
::
ostringstream
os
;
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
LOG
(
INFO
)
<<
"msg["
<<
i
<<
"]="
<<
*
messages
[
i
]
<<
noflush
;
os
<<
"msg["
<<
i
<<
"]="
<<
*
messages
[
i
]
;
}
}
LOG
(
INFO
);
LOG
(
INFO
)
<<
"Received from Stream="
<<
id
<<
": "
<<
os
.
str
()
;
return
0
;
return
0
;
}
}
virtual
void
on_idle_timeout
(
brpc
::
StreamId
id
)
{
virtual
void
on_idle_timeout
(
brpc
::
StreamId
id
)
{
...
...
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