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
a13730a4
Commit
a13730a4
authored
May 07, 2019
by
helei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add explicit key word
parent
cc6642bd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
19 deletions
+75
-19
adaptive_connection_type.h
src/brpc/adaptive_connection_type.h
+5
-5
adaptive_max_concurrency.h
src/brpc/adaptive_max_concurrency.h
+7
-7
adaptive_protocol_type.h
src/brpc/adaptive_protocol_type.h
+7
-7
server.cpp
src/brpc/server.cpp
+0
-0
brpc_adaptive_class_unittest.cpp
test/brpc_adaptive_class_unittest.cpp
+56
-0
No files found.
src/brpc/adaptive_connection_type.h
View file @
a13730a4
// Copyright (c) 2015 Baidu, Inc.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
...
@@ -38,7 +38,7 @@ const char* ConnectionTypeToString(ConnectionType);
// Assignable by both ConnectionType and names.
class
AdaptiveConnectionType
{
public
:
public
:
AdaptiveConnectionType
()
:
_type
(
CONNECTION_TYPE_UNKNOWN
),
_error
(
false
)
{}
AdaptiveConnectionType
(
ConnectionType
type
)
:
_type
(
type
),
_error
(
false
)
{}
~
AdaptiveConnectionType
()
{}
...
...
@@ -52,7 +52,7 @@ public:
operator
ConnectionType
()
const
{
return
_type
;
}
const
char
*
name
()
const
{
return
ConnectionTypeToString
(
_type
);
}
bool
has_error
()
const
{
return
_error
;
}
private
:
ConnectionType
_type
;
// Since this structure occupies 8 bytes in 64-bit machines anyway,
...
...
src/brpc/adaptive_max_concurrency.h
View file @
a13730a4
// Copyright (c) 2014 Baidu, Inc.G
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
...
...
@@ -27,13 +27,13 @@ namespace brpc {
class
AdaptiveMaxConcurrency
{
public
:
AdaptiveMaxConcurrency
();
AdaptiveMaxConcurrency
(
int
max_concurrency
);
AdaptiveMaxConcurrency
(
const
butil
::
StringPiece
&
value
);
// Non-trivial destructor to prevent AdaptiveMaxConcurrency from being
explicit
AdaptiveMaxConcurrency
();
explicit
AdaptiveMaxConcurrency
(
int
max_concurrency
);
explicit
AdaptiveMaxConcurrency
(
const
butil
::
StringPiece
&
value
);
// Non-trivial destructor to prevent AdaptiveMaxConcurrency from being
// passed to variadic arguments without explicit type conversion.
// eg:
// eg:
// printf("%d", options.max_concurrency) // compile error
// printf("%s", options.max_concurrency.value().c_str()) // ok
~
AdaptiveMaxConcurrency
()
{}
...
...
src/brpc/adaptive_protocol_type.h
View file @
a13730a4
// Copyright (c) 2015 Baidu, Inc.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
...
@@ -38,9 +38,9 @@ const char* ProtocolTypeToString(ProtocolType);
// Assignable by both ProtocolType and names.
class
AdaptiveProtocolType
{
public
:
AdaptiveProtocolType
()
:
_type
(
PROTOCOL_UNKNOWN
)
{}
AdaptiveProtocolType
(
ProtocolType
type
)
:
_type
(
type
)
{}
public
:
explicit
AdaptiveProtocolType
()
:
_type
(
PROTOCOL_UNKNOWN
)
{}
explicit
AdaptiveProtocolType
(
ProtocolType
type
)
:
_type
(
type
)
{}
~
AdaptiveProtocolType
()
{}
void
operator
=
(
ProtocolType
type
)
{
...
...
@@ -77,7 +77,7 @@ public:
bool
has_param
()
const
{
return
!
_param
.
empty
();
}
const
std
::
string
&
param
()
const
{
return
_param
;
}
private
:
ProtocolType
_type
;
std
::
string
_name
;
...
...
src/brpc/server.cpp
View file @
a13730a4
This diff is collapsed.
Click to expand it.
test/brpc_adaptive_class_unittest.cpp
0 → 100755
View file @
a13730a4
// brpc - A framework to host and access services throughout Baidu.
// Copyright (c) 2014 Baidu, Inc.
// Date: 2019/04/16 23:41:04
#include <gtest/gtest.h>
#include "brpc/adaptive_max_concurrency.h"
#include "brpc/adaptive_protocol_type.h"
#include "brpc/adaptive_connection_type.h"
const
std
::
string
kAutoCL
=
"aUto"
;
const
std
::
string
kHttp
=
"hTTp"
;
const
std
::
string
kPooled
=
"PoOled"
;
TEST
(
AdaptiveMaxConcurrencyTest
,
ShouldConvertCorrectly
)
{
brpc
::
AdaptiveMaxConcurrency
amc
(
0
);
EXPECT_EQ
(
brpc
::
AdaptiveMaxConcurrency
::
UNLIMITED
(),
amc
.
type
());
EXPECT_EQ
(
brpc
::
AdaptiveMaxConcurrency
::
UNLIMITED
(),
amc
.
value
());
EXPECT_EQ
(
0
,
int
(
amc
));
EXPECT_TRUE
(
amc
==
brpc
::
AdaptiveMaxConcurrency
::
UNLIMITED
());
amc
=
10
;
EXPECT_EQ
(
brpc
::
AdaptiveMaxConcurrency
::
CONSTANT
(),
amc
.
type
());
EXPECT_EQ
(
"10"
,
amc
.
value
());
EXPECT_EQ
(
10
,
int
(
amc
));
EXPECT_EQ
(
amc
,
"10"
);
amc
=
kAutoCL
;
EXPECT_EQ
(
kAutoCL
,
amc
.
type
());
EXPECT_EQ
(
kAutoCL
,
amc
.
value
());
EXPECT_EQ
(
int
(
amc
),
-
1
);
EXPECT_TRUE
(
amc
==
"auto"
);
}
TEST
(
AdaptiveProtocolType
,
ShouldConvertCorrectly
)
{
brpc
::
AdaptiveProtocolType
apt
;
apt
=
kHttp
;
EXPECT_EQ
(
apt
,
brpc
::
ProtocolType
::
PROTOCOL_HTTP
);
apt
=
brpc
::
ProtocolType
::
PROTOCOL_HTTP
;
EXPECT_EQ
(
apt
,
brpc
::
ProtocolType
::
PROTOCOL_HTTP
);
}
TEST
(
AdaptiveConnectionTypeTest
,
ShouldConvertCorrectly
)
{
brpc
::
AdaptiveConnectionType
act
;
act
=
brpc
::
ConnectionType
::
CONNECTION_TYPE_POOLED
;
EXPECT_EQ
(
act
,
brpc
::
ConnectionType
::
CONNECTION_TYPE_POOLED
);
act
=
kPooled
;
EXPECT_EQ
(
act
,
brpc
::
ConnectionType
::
CONNECTION_TYPE_POOLED
);
}
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