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
b680407e
Commit
b680407e
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
c wrapper: add callback to free listen context data
parent
6caf4b0d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
c/opendht.cpp
+16
-2
16 additions, 2 deletions
c/opendht.cpp
c/opendht_c.h
+1
-1
1 addition, 1 deletion
c/opendht_c.h
tools/dhtcnode.c
+1
-1
1 addition, 1 deletion
tools/dhtcnode.c
with
18 additions
and
4 deletions
c/opendht.cpp
+
16
−
2
View file @
b680407e
...
...
@@ -206,11 +206,25 @@ void dht_runner_get(dht_runner* r, const dht_infohash* h, dht_get_cb cb, dht_don
});
}
dht_op_token
*
dht_runner_listen
(
dht_runner
*
r
,
const
dht_infohash
*
h
,
dht_value_cb
cb
,
void
*
cb_user_data
)
{
struct
ScopeGuardCb
{
ScopeGuardCb
(
dht_shutdown_cb
cb
,
void
*
data
)
:
onDestroy
(
cb
),
userData
(
data
)
{}
~
ScopeGuardCb
()
{
if
(
onDestroy
)
onDestroy
((
void
*
)
userData
);
}
private
:
const
dht_shutdown_cb
onDestroy
;
void
const
*
userData
;
};
dht_op_token
*
dht_runner_listen
(
dht_runner
*
r
,
const
dht_infohash
*
h
,
dht_value_cb
cb
,
dht_shutdown_cb
done_cb
,
void
*
cb_user_data
)
{
auto
runner
=
reinterpret_cast
<
dht
::
DhtRunner
*>
(
r
);
auto
hash
=
reinterpret_cast
<
const
dht
::
InfoHash
*>
(
h
);
auto
fret
=
new
std
::
future
<
size_t
>
;
*
fret
=
runner
->
listen
(
*
hash
,
[
cb
,
cb_user_data
](
const
std
::
vector
<
std
::
shared_ptr
<
dht
::
Value
>>&
values
,
bool
expired
)
{
auto
guard
=
done_cb
?
std
::
make_shared
<
ScopeGuardCb
>
(
done_cb
,
cb_user_data
)
:
std
::
shared_ptr
<
ScopeGuardCb
>
{};
*
fret
=
runner
->
listen
(
*
hash
,
[
cb
,
cb_user_data
,
guard
](
const
std
::
vector
<
std
::
shared_ptr
<
dht
::
Value
>>&
values
,
bool
expired
)
{
for
(
const
auto
&
value
:
values
)
{
if
(
not
cb
(
reinterpret_cast
<
const
dht_value
*>
(
&
value
),
expired
,
cb_user_data
))
return
false
;
...
...
This diff is collapsed.
Click to expand it.
c/opendht_c.h
+
1
−
1
View file @
b680407e
...
...
@@ -127,7 +127,7 @@ OPENDHT_C_PUBLIC void dht_runner_run_config(dht_runner* runner, in_port_t port,
OPENDHT_C_PUBLIC
void
dht_runner_ping
(
dht_runner
*
runner
,
struct
sockaddr
*
addr
,
socklen_t
addr_len
);
OPENDHT_C_PUBLIC
void
dht_runner_bootstrap
(
dht_runner
*
runner
,
const
char
*
host
,
const
char
*
service
);
OPENDHT_C_PUBLIC
void
dht_runner_get
(
dht_runner
*
runner
,
const
dht_infohash
*
hash
,
dht_get_cb
cb
,
dht_done_cb
done_cb
,
void
*
cb_user_data
);
OPENDHT_C_PUBLIC
dht_op_token
*
dht_runner_listen
(
dht_runner
*
runner
,
const
dht_infohash
*
hash
,
dht_value_cb
cb
,
void
*
cb_user_data
);
OPENDHT_C_PUBLIC
dht_op_token
*
dht_runner_listen
(
dht_runner
*
runner
,
const
dht_infohash
*
hash
,
dht_value_cb
cb
,
dht_shutdown_cb
done_cb
,
void
*
cb_user_data
);
OPENDHT_C_PUBLIC
void
dht_runner_cancel_listen
(
dht_runner
*
runner
,
const
dht_infohash
*
hash
,
dht_op_token
*
token
);
OPENDHT_C_PUBLIC
void
dht_runner_put
(
dht_runner
*
runner
,
const
dht_infohash
*
hash
,
const
dht_value
*
value
,
dht_done_cb
done_cb
,
void
*
cb_user_data
);
OPENDHT_C_PUBLIC
void
dht_runner_shutdown
(
dht_runner
*
runner
,
dht_shutdown_cb
done_cb
,
void
*
cb_user_data
);
...
...
This diff is collapsed.
Click to expand it.
tools/dhtcnode.c
+
1
−
1
View file @
b680407e
...
...
@@ -44,7 +44,7 @@ int main()
dht_runner_get
(
runner
,
&
h
,
dht_get_callback
,
dht_done_callback
,
runner
);
// Listen for data
dht_op_token
*
token
=
dht_runner_listen
(
runner
,
&
h
,
dht_value_callback
,
runner
);
dht_op_token
*
token
=
dht_runner_listen
(
runner
,
&
h
,
dht_value_callback
,
NULL
,
runner
);
sleep
(
1
);
...
...
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