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
f938d486
Commit
f938d486
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
c wrapper: add listen context to dhtcnode
parent
76b4da08
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/dhtcnode.c
+17
-2
17 additions, 2 deletions
tools/dhtcnode.c
with
17 additions
and
2 deletions
tools/dhtcnode.c
+
17
−
2
View file @
f938d486
...
@@ -3,10 +3,15 @@
...
@@ -3,10 +3,15 @@
#include
<stdio.h>
#include
<stdio.h>
#include
<string.h>
#include
<string.h>
#include
<unistd.h>
#include
<unistd.h>
#include
<stdlib.h>
struct
op_context
{
dht_runner
*
runner
;
int
d
;
};
bool
dht_value_callback
(
const
dht_value
*
value
,
bool
expired
,
void
*
user_data
)
bool
dht_value_callback
(
const
dht_value
*
value
,
bool
expired
,
void
*
user_data
)
{
{
dht_runner
*
runner
=
(
dht_runner
*
)
user_data
;
dht_data_view
data
=
dht_value_get_data
(
value
);
dht_data_view
data
=
dht_value_get_data
(
value
);
printf
(
"Value callback %s: %.*s.
\n
"
,
expired
?
"expired"
:
"new"
,
(
int
)
data
.
size
,
data
.
data
);
printf
(
"Value callback %s: %.*s.
\n
"
,
expired
?
"expired"
:
"new"
,
(
int
)
data
.
size
,
data
.
data
);
}
}
...
@@ -24,6 +29,13 @@ bool dht_done_callback(bool ok, void* user_data)
...
@@ -24,6 +29,13 @@ bool dht_done_callback(bool ok, void* user_data)
printf
(
"Done callback. %s
\n
"
,
ok
?
"Success !"
:
"Failure :-("
);
printf
(
"Done callback. %s
\n
"
,
ok
?
"Success !"
:
"Failure :-("
);
}
}
bool
op_context_free
(
void
*
user_data
)
{
struct
op_context
*
ctx
=
(
struct
op_context
*
)
user_data
;
printf
(
"op_context_free %d.
\n
"
,
ctx
->
d
);
free
(
ctx
);
}
int
main
()
int
main
()
{
{
dht_runner
*
runner
=
dht_runner_new
();
dht_runner
*
runner
=
dht_runner_new
();
...
@@ -44,7 +56,10 @@ int main()
...
@@ -44,7 +56,10 @@ int main()
dht_runner_get
(
runner
,
&
h
,
dht_get_callback
,
dht_done_callback
,
runner
);
dht_runner_get
(
runner
,
&
h
,
dht_get_callback
,
dht_done_callback
,
runner
);
// Listen for data
// Listen for data
dht_op_token
*
token
=
dht_runner_listen
(
runner
,
&
h
,
dht_value_callback
,
NULL
,
runner
);
struct
op_context
*
ctx
=
malloc
(
sizeof
(
struct
op_context
));
ctx
->
runner
=
runner
;
ctx
->
d
=
42
;
dht_op_token
*
token
=
dht_runner_listen
(
runner
,
&
h
,
dht_value_callback
,
op_context_free
,
ctx
);
sleep
(
1
);
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