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
591dae77
Commit
591dae77
authored
Jul 17, 2018
by
Ge Jun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
include boost/make_shared on demand & suppress some strict aliasing warning
parent
0542ba7f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
8 deletions
+18
-8
native_client.cpp
example/thrift_extension_c++/native_client.cpp
+1
-0
native_server.cpp
example/thrift_extension_c++/native_server.cpp
+1
-0
thrift_protocol.cpp
src/brpc/policy/thrift_protocol.cpp
+16
-8
No files found.
example/thrift_extension_c++/native_client.cpp
View file @
591dae77
...
...
@@ -29,6 +29,7 @@
# define THRIFT_STDCXX apache::thrift::stdcxx
#else
# define THRIFT_STDCXX boost
# include <boost/make_shared.hpp>
#endif
#endif
...
...
example/thrift_extension_c++/native_server.cpp
View file @
591dae77
...
...
@@ -35,6 +35,7 @@
#include <thrift/transport/TNonblockingServerSocket.h>
#else
# define THRIFT_STDCXX boost
# include <boost/make_shared.hpp>
#endif
#endif
...
...
src/brpc/policy/thrift_protocol.cpp
View file @
591dae77
...
...
@@ -44,6 +44,7 @@
# define THRIFT_STDCXX apache::thrift::stdcxx
#else
# define THRIFT_STDCXX boost
# include <boost/make_shared.hpp>
#endif
#endif
...
...
@@ -72,15 +73,15 @@ ReadThriftMessageBegin(butil::IOBuf* body,
// Version + Message type + Length + Method + Sequence Id
// | | | | |
// 3 + 1 + 4 + >0 + 4
char
version_and_len_buf
[
8
];
uint32_t
version_and_len_buf
[
2
];
size_t
k
=
body
->
copy_to
(
version_and_len_buf
,
sizeof
(
version_and_len_buf
));
if
(
k
!=
sizeof
(
version_and_len_buf
)
)
{
return
butil
::
Status
(
-
1
,
"Fail to copy %"
PRIu64
" bytes from body"
,
sizeof
(
version_and_len_buf
));
}
*
mtype
=
(
apache
::
thrift
::
protocol
::
TMessageType
)
(
ntohl
(
*
(
uint32_t
*
)
version_and_len_buf
)
&
0x000000FF
);
const
uint32_t
method_name_length
=
ntohl
(
*
(
uint32_t
*
)(
version_and_len_buf
+
4
)
);
(
ntohl
(
version_and_len_buf
[
0
]
)
&
0x000000FF
);
const
uint32_t
method_name_length
=
ntohl
(
version_and_len_buf
[
1
]
);
if
(
method_name_length
>
MAX_THRIFT_METHOD_NAME_LENGTH
)
{
return
butil
::
Status
(
-
1
,
"method_name_length=%u is too long"
,
method_name_length
);
...
...
@@ -92,7 +93,9 @@ ReadThriftMessageBegin(butil::IOBuf* body,
return
butil
::
Status
(
-
1
,
"Fail to cut %"
PRIu64
" bytes"
,
sizeof
(
buf
));
}
method_name
->
assign
(
buf
+
sizeof
(
version_and_len_buf
),
method_name_length
);
*
seq_id
=
ntohl
(
*
(
uint32_t
*
)(
buf
+
sizeof
(
version_and_len_buf
)
+
method_name_length
));
// suppress strict-aliasing warning
uint32_t
*
p_seq_id
=
(
uint32_t
*
)(
buf
+
sizeof
(
version_and_len_buf
)
+
method_name_length
);
*
seq_id
=
ntohl
(
*
p_seq_id
);
return
butil
::
Status
::
OK
();
}
...
...
@@ -317,7 +320,9 @@ void ThriftClosure::DoRun() {
}
else
{
const
size_t
mb_size
=
ThriftMessageBeginSize
(
method_name
);
char
buf
[
sizeof
(
thrift_head_t
)
+
mb_size
];
((
thrift_head_t
*
)
buf
)
->
body_len
=
htonl
(
mb_size
+
_response
.
body
.
size
());
// suppress strict-aliasing warning
thrift_head_t
*
head
=
(
thrift_head_t
*
)
buf
;
head
->
body_len
=
htonl
(
mb_size
+
_response
.
body
.
size
());
WriteThriftMessageBegin
(
buf
+
sizeof
(
thrift_head_t
),
method_name
,
::
apache
::
thrift
::
protocol
::
T_REPLY
,
seq_id
);
write_buf
.
append
(
buf
,
sizeof
(
buf
));
...
...
@@ -364,8 +369,9 @@ ParseResult ParseThriftMessage(butil::IOBuf* source,
<<
" doesn't match THRIFT_VERSION="
<<
THRIFT_HEAD_VERSION_1
;
return
MakeParseError
(
PARSE_ERROR_TRY_OTHERS
);
}
const
uint32_t
body_len
=
ntohl
(((
thrift_head_t
*
)
header_buf
)
->
body_len
);
// suppress strict-aliasing warning
thrift_head_t
*
head
=
(
thrift_head_t
*
)
header_buf
;
const
uint32_t
body_len
=
ntohl
(
head
->
body_len
);
if
(
body_len
>
FLAGS_max_body_size
)
{
return
MakeParseError
(
PARSE_ERROR_TOO_BIG_DATA
);
}
else
if
(
source
->
length
()
<
sizeof
(
thrift_head_t
)
+
body_len
)
{
...
...
@@ -700,7 +706,9 @@ void SerializeThriftRequest(butil::IOBuf* request_buf, Controller* cntl,
}
else
{
const
size_t
mb_size
=
ThriftMessageBeginSize
(
method_name
);
char
buf
[
sizeof
(
thrift_head_t
)
+
mb_size
];
((
thrift_head_t
*
)
buf
)
->
body_len
=
htonl
(
mb_size
+
req
->
body
.
size
());
// suppress strict-aliasing warning
thrift_head_t
*
head
=
(
thrift_head_t
*
)
buf
;
head
->
body_len
=
htonl
(
mb_size
+
req
->
body
.
size
());
WriteThriftMessageBegin
(
buf
+
sizeof
(
thrift_head_t
),
method_name
,
::
apache
::
thrift
::
protocol
::
T_CALL
,
0
/*seq_id*/
);
request_buf
->
append
(
buf
,
sizeof
(
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