Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
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
savoirfairelinux
opendht
Commits
29fe7d5f
Commit
29fe7d5f
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
http: add Resolver
parent
459217b6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/http.h
+19
-2
19 additions, 2 deletions
include/opendht/http.h
src/http.cpp
+39
-0
39 additions, 0 deletions
src/http.cpp
with
58 additions
and
2 deletions
include/opendht/http.h
+
19
−
2
View file @
29fe7d5f
...
...
@@ -104,6 +104,22 @@ private:
std
::
shared_ptr
<
dht
::
Logger
>
logger_
;
};
class
Resolver
{
Resolver
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
host
,
const
std
::
string
&
service
=
"80"
);
using
ResolvedCb
=
std
::
function
<
void
(
const
asio
::
error_code
&
,
const
asio
::
ip
::
basic_resolver_results
<
asio
::
ip
::
tcp
>&
)
>
;
void
addOnResolved
(
ResolvedCb
cb
);
private:
std
::
mutex
cbsMutex_
;
asio
::
ip
::
tcp
::
resolver
resolver_
;
asio
::
error_code
error_
;
asio
::
ip
::
basic_resolver_results
<
asio
::
ip
::
tcp
>
endpoints_
;
std
::
queue
<
ResolvedCb
>
cbs_
;
bool
completed_
{
false
};
};
class
OPENDHT_PUBLIC
Request
{
public:
...
...
@@ -138,12 +154,13 @@ private:
size_t
get_content_length
(
const
std
::
string
str
);
std
::
string
service_
;
Resolver
resolver_
;
/* std::string service_;
std::string host_;
asio::ip::tcp::resolver resolver_;
asio::ip::basic_resolver_results<asio::ip::tcp> endpoints_;
*/
Id
id_
;
static
Id
ids_
;
std
::
shared_ptr
<
Connection
>
conn_
;
...
...
This diff is collapsed.
Click to expand it.
src/http.cpp
+
39
−
0
View file @
29fe7d5f
...
...
@@ -477,4 +477,43 @@ Request::get_content_length(const std::string str)
return
content_length
;
}
Resolver
::
Resolver
(
asio
::
io_context
&
ctx
,
const
std
::
string
&
host
,
const
std
::
string
&
service
)
{
resolver_
.
async_resolve
({
host
,
service
},
[
this
]
(
const
asio
::
error_code
&
ec
,
asio
::
ip
::
tcp
::
resolver
::
results_type
endpoints
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
cbsMutex_
);
while
(
not
cbs_
.
empty
())
{
cbs_
.
front
()(
ec
,
endpoints
);
cbs_
.
pop
();
}
error_
=
ec
;
endpoints_
=
endpoints
;
completed_
=
true
;
}
}
void
Resolver
::
addOnResolved
(
ResolvedCb
cb
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
cbsMutex_
);
if
(
completed_
)
{
cb
(
error_
,
endpoints_
);
}
else
{
cbs_
.
push
(
std
::
move
(
cb
));
}
}
/*
private:
std::mutex cbsMutex_;
std::queue<ResolvedCb> cbs_;
asio::ip::tcp::resolver resolver_;
asio::error_code error_;
asio::ip::basic_resolver_results<asio::ip::tcp> endpoints_;
} */
}
// namespace http
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