Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
1e8b1ddf
Unverified
Commit
1e8b1ddf
authored
Jan 24, 2020
by
Dennis Jenkins
Committed by
GitHub
Jan 24, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #684 from hyperxor/remove_friend_relationship_in_connection
Remove friend relationship in Connection class
parents
54e2bc98
9ed23474
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
include/pistache/client.h
include/pistache/client.h
+2
-3
src/client/client.cc
src/client/client.cc
+12
-5
No files found.
include/pistache/client.h
View file @
1e8b1ddf
...
...
@@ -27,13 +27,10 @@
namespace
Pistache
{
namespace
Http
{
class
ConnectionPool
;
class
Transport
;
struct
Connection
:
public
std
::
enable_shared_from_this
<
Connection
>
{
friend
class
ConnectionPool
;
using
OnDone
=
std
::
function
<
void
()
>
;
Connection
();
...
...
@@ -58,6 +55,8 @@ struct Connection : public std::enable_shared_from_this<Connection> {
void
connect
(
const
Address
&
addr
);
void
close
();
bool
isIdle
()
const
;
bool
tryUse
();
void
setAsIdle
();
bool
isConnected
()
const
;
bool
hasTransport
()
const
;
void
associateTransport
(
const
std
::
shared_ptr
<
Transport
>
&
transport
);
...
...
src/client/client.cc
View file @
1e8b1ddf
...
...
@@ -425,6 +425,16 @@ bool Connection::isIdle() const {
Connection
::
State
::
Idle
;
}
bool
Connection
::
tryUse
()
{
auto
curState
=
static_cast
<
uint32_t
>
(
Connection
::
State
::
Idle
);
auto
newState
=
static_cast
<
uint32_t
>
(
Connection
::
State
::
Used
);
return
state_
.
compare_exchange_strong
(
curState
,
newState
);
}
void
Connection
::
setAsIdle
()
{
state_
.
store
(
static_cast
<
uint32_t
>
(
Connection
::
State
::
Idle
));
}
bool
Connection
::
isConnected
()
const
{
return
connectionState_
.
load
()
==
Connected
;
}
...
...
@@ -583,10 +593,7 @@ ConnectionPool::pickConnection(const std::string &domain) {
}
for
(
auto
&
conn
:
pool
)
{
auto
&
state
=
conn
->
state_
;
auto
curState
=
static_cast
<
uint32_t
>
(
Connection
::
State
::
Idle
);
auto
newState
=
static_cast
<
uint32_t
>
(
Connection
::
State
::
Used
);
if
(
state
.
compare_exchange_strong
(
curState
,
newState
))
{
if
(
conn
->
tryUse
())
{
return
conn
;
}
}
...
...
@@ -596,7 +603,7 @@ ConnectionPool::pickConnection(const std::string &domain) {
void
ConnectionPool
::
releaseConnection
(
const
std
::
shared_ptr
<
Connection
>
&
connection
)
{
connection
->
s
tate_
.
store
(
static_cast
<
uint32_t
>
(
Connection
::
State
::
Idle
)
);
connection
->
s
etAsIdle
(
);
}
size_t
ConnectionPool
::
usedConnections
(
const
std
::
string
&
domain
)
const
{
...
...
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