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
9ed23474
Commit
9ed23474
authored
Jan 24, 2020
by
hyperxor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove friend relationship in Connection class
parent
54e2bc98
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 @
9ed23474
...
@@ -27,13 +27,10 @@
...
@@ -27,13 +27,10 @@
namespace
Pistache
{
namespace
Pistache
{
namespace
Http
{
namespace
Http
{
class
ConnectionPool
;
class
Transport
;
class
Transport
;
struct
Connection
:
public
std
::
enable_shared_from_this
<
Connection
>
{
struct
Connection
:
public
std
::
enable_shared_from_this
<
Connection
>
{
friend
class
ConnectionPool
;
using
OnDone
=
std
::
function
<
void
()
>
;
using
OnDone
=
std
::
function
<
void
()
>
;
Connection
();
Connection
();
...
@@ -58,6 +55,8 @@ struct Connection : public std::enable_shared_from_this<Connection> {
...
@@ -58,6 +55,8 @@ struct Connection : public std::enable_shared_from_this<Connection> {
void
connect
(
const
Address
&
addr
);
void
connect
(
const
Address
&
addr
);
void
close
();
void
close
();
bool
isIdle
()
const
;
bool
isIdle
()
const
;
bool
tryUse
();
void
setAsIdle
();
bool
isConnected
()
const
;
bool
isConnected
()
const
;
bool
hasTransport
()
const
;
bool
hasTransport
()
const
;
void
associateTransport
(
const
std
::
shared_ptr
<
Transport
>
&
transport
);
void
associateTransport
(
const
std
::
shared_ptr
<
Transport
>
&
transport
);
...
...
src/client/client.cc
View file @
9ed23474
...
@@ -425,6 +425,16 @@ bool Connection::isIdle() const {
...
@@ -425,6 +425,16 @@ bool Connection::isIdle() const {
Connection
::
State
::
Idle
;
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
{
bool
Connection
::
isConnected
()
const
{
return
connectionState_
.
load
()
==
Connected
;
return
connectionState_
.
load
()
==
Connected
;
}
}
...
@@ -583,10 +593,7 @@ ConnectionPool::pickConnection(const std::string &domain) {
...
@@ -583,10 +593,7 @@ ConnectionPool::pickConnection(const std::string &domain) {
}
}
for
(
auto
&
conn
:
pool
)
{
for
(
auto
&
conn
:
pool
)
{
auto
&
state
=
conn
->
state_
;
if
(
conn
->
tryUse
())
{
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
))
{
return
conn
;
return
conn
;
}
}
}
}
...
@@ -596,7 +603,7 @@ ConnectionPool::pickConnection(const std::string &domain) {
...
@@ -596,7 +603,7 @@ ConnectionPool::pickConnection(const std::string &domain) {
void
ConnectionPool
::
releaseConnection
(
void
ConnectionPool
::
releaseConnection
(
const
std
::
shared_ptr
<
Connection
>
&
connection
)
{
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
{
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