Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
mtxclient
Commits
3ac3a5cb
Commit
3ac3a5cb
authored
6 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Remove unused code
parent
ffecb194
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/client.cpp
+1
-50
1 addition, 50 deletions
src/client.cpp
src/client.hpp
+3
-10
3 additions, 10 deletions
src/client.hpp
src/session.hpp
+0
-3
0 additions, 3 deletions
src/session.hpp
with
4 additions
and
63 deletions
src/client.cpp
+
1
−
50
View file @
3ac3a5cb
...
...
@@ -43,16 +43,6 @@ Client::on_resolve(std::shared_ptr<Session> s,
if
(
ec
)
return
s
->
on_failure
(
s
->
id
,
ec
);
// Add new session to the list of active sessions so that we can access
// it if the user decides to cancel the corresponding request before
// it completes.
// Because active sessions list can be accessed from multiple threads,
//
// we guard it with a mutex to avoid data corruption.
std
::
unique_lock
<
std
::
mutex
>
lock
(
active_sessions_guard_
);
active_sessions_
[
s
->
id
]
=
s
;
lock
.
unlock
();
boost
::
asio
::
async_connect
(
s
->
socket
.
next_layer
(),
results
.
begin
(),
...
...
@@ -68,10 +58,6 @@ Client::on_connect(std::shared_ptr<Session> s, boost::system::error_code ec)
return
s
->
on_failure
(
s
->
id
,
ec
);
}
// Check if the request is already cancelled and we shouldn't move forward.
if
(
s
->
is_cancelled
)
return
on_request_complete
(
s
);
// Perform the SSL handshake
s
->
socket
.
async_handshake
(
boost
::
asio
::
ssl
::
stream_base
::
client
,
...
...
@@ -86,10 +72,6 @@ Client::on_handshake(std::shared_ptr<Session> s, boost::system::error_code ec)
return
s
->
on_failure
(
s
->
id
,
ec
);
}
// Check if the request is already cancelled and we shouldn't move forward.
if
(
s
->
is_cancelled
)
return
on_request_complete
(
s
);
boost
::
beast
::
http
::
async_write
(
s
->
socket
,
s
->
request
,
std
::
bind
(
&
Client
::
on_write
,
...
...
@@ -111,9 +93,6 @@ Client::on_write(std::shared_ptr<Session> s,
return
s
->
on_failure
(
s
->
id
,
ec
);
}
if
(
s
->
is_cancelled
)
return
on_request_complete
(
s
);
// Receive the HTTP response
http
::
async_read
(
s
->
socket
,
...
...
@@ -148,16 +127,6 @@ Client::do_request(std::shared_ptr<Session> s)
std
::
placeholders
::
_2
));
}
void
Client
::
cancel_request
(
RequestID
request_id
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
active_sessions_guard_
);
auto
it
=
active_sessions_
.
find
(
request_id
);
if
(
it
!=
active_sessions_
.
end
())
it
->
second
->
is_cancelled
=
true
;
}
void
Client
::
remove_session
(
std
::
shared_ptr
<
Session
>
s
)
{
...
...
@@ -182,15 +151,6 @@ Client::remove_session(std::shared_ptr<Session> s)
// TODO: propagate the error.
std
::
cout
<<
"shutdown: "
<<
ec
.
message
()
<<
std
::
endl
;
});
// Remove the session from the map of active sessions.
std
::
unique_lock
<
std
::
mutex
>
lock
(
active_sessions_guard_
);
auto
it
=
active_sessions_
.
find
(
s
->
id
);
if
(
it
!=
active_sessions_
.
end
())
active_sessions_
.
erase
(
it
);
lock
.
unlock
();
}
void
...
...
@@ -198,16 +158,7 @@ Client::on_request_complete(std::shared_ptr<Session> s)
{
remove_session
(
s
);
boost
::
system
::
error_code
ec
;
if
(
s
->
error_code
==
0
&&
s
->
is_cancelled
)
{
ec
=
boost
::
asio
::
error
::
operation_aborted
;
s
->
on_failure
(
s
->
id
,
ec
);
return
;
}
else
{
ec
=
s
->
error_code
;
}
boost
::
system
::
error_code
ec
(
s
->
error_code
);
s
->
on_success
(
s
->
id
,
s
->
parser
.
get
(),
ec
);
}
...
...
This diff is collapsed.
Click to expand it.
src/client.hpp
+
3
−
10
View file @
3ac3a5cb
...
...
@@ -12,10 +12,11 @@
#include
<boost/thread/thread.hpp>
#include
<json.hpp>
#include
<mtx/requests.hpp>
#include
<mtx/responses.hpp>
#include
"crypto.hpp"
#include
"errors.hpp"
#include
"mtx/requests.hpp"
#include
"mtx/responses.hpp"
#include
"session.hpp"
#include
"utils.hpp"
...
...
@@ -45,12 +46,8 @@ public:
//! Wait for the client to close.
void
close
();
//! Cancels the request.
void
cancel_request
(
RequestID
request_id
);
//! Make a new request.
void
do_request
(
std
::
shared_ptr
<
Session
>
session
);
//! Return the number of pending requests.
int
active_sessions
()
const
{
return
active_sessions_
.
size
();
}
//! Add an access token.
void
set_access_token
(
const
std
::
string
&
token
)
{
access_token_
=
token
;
}
//! Retrieve the access token.
...
...
@@ -267,10 +264,6 @@ private:
boost
::
asio
::
io_service
ios_
;
//! Keeps tracks for the active sessions.
std
::
map
<
RequestID
,
std
::
shared_ptr
<
Session
>>
active_sessions_
;
//! Used to synchronize access to `active_sessions_`.
std
::
mutex
active_sessions_guard_
;
//! Used to prevent the event loop from shutting down.
std
::
unique_ptr
<
boost
::
asio
::
io_service
::
work
>
work_
;
//! Worker threads for the requests.
...
...
This diff is collapsed.
Click to expand it.
src/session.hpp
+
0
−
3
View file @
3ac3a5cb
...
...
@@ -36,7 +36,6 @@ struct Session
,
id
{
id
}
,
on_success
{
on_success
}
,
on_failure
{
on_failure
}
,
is_cancelled
{
false
}
{
parser
.
header_limit
(
8192
);
parser
.
body_limit
(
1
*
1024
*
1024
*
1024
);
// 1 GiB
...
...
@@ -61,8 +60,6 @@ struct Session
SuccessCallback
on_success
;
//! Function to be called when the request fails.
FailureCallback
on_failure
;
//! Whether or not the request has been cancelled.
std
::
atomic_bool
is_cancelled
;
};
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment