aboutsummaryrefslogtreecommitdiff
path: root/src/dhtu/testing_dhtu_cmd_send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dhtu/testing_dhtu_cmd_send.c')
-rw-r--r--src/dhtu/testing_dhtu_cmd_send.c60
1 files changed, 4 insertions, 56 deletions
diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c
index 129a31205..e620e329e 100644
--- a/src/dhtu/testing_dhtu_cmd_send.c
+++ b/src/dhtu/testing_dhtu_cmd_send.c
@@ -34,16 +34,10 @@ struct SendState
34{ 34{
35 35
36 /** 36 /**
37 * Function to call when done. 37 * Mandatory context for async commands.
38 */ 38 */
39 GNUNET_SCHEDULER_TaskCallback cont; 39 struct GNUNET_TESTING_AsyncContext ac;
40 40
41 /**
42 * Closure for @e cont.
43 */
44 void *cont_cls;
45
46 enum GNUNET_GenericReturnValue finished;
47}; 41};
48 42
49 43
@@ -98,56 +92,10 @@ send_run (void *cls,
98 GNUNET_TESTING_get_trait_XXX (other_cmd, 92 GNUNET_TESTING_get_trait_XXX (other_cmd,
99 &data); 93 &data);
100#endif 94#endif
101 ss->finished = GNUNET_OK; 95 GNUNET_TESTING_async_finish (&ss->ac);
102} 96}
103 97
104 98
105/**
106 * This function checks the flag NetJailState#finished, if this cmd finished.
107 *
108 * @param cls a `struct SendState`
109 * @param cont function to call upon completion, can be NULL
110 * @param cont_cls closure for @a cont
111 * @return
112 * #GNUNET_NO if the command is still running and @a cont will be called later
113 * #GNUNET_OK if the command completed successfully and @a cont was called
114 * #GNUNET_SYSERR if the operation @a cont was NOT called
115 */
116static enum GNUNET_GenericReturnValue
117send_finish (void *cls,
118 GNUNET_SCHEDULER_TaskCallback cont,
119 void *cont_cls)
120{
121 struct SendState *ss = cls;
122
123 switch (ss->finished)
124 {
125 case GNUNET_OK:
126 cont (cont_cls);
127 break;
128 case GNUNET_SYSERR:
129 GNUNET_break (0);
130 break;
131 case GNUNET_NO:
132 if (NULL != ss->cont)
133 {
134 GNUNET_break (0);
135 return GNUNET_SYSERR;
136 }
137 ss->cont = cont;
138 ss->cont_cls = cont_cls;
139 break;
140 }
141 return ss->finished;
142}
143
144
145/**
146 * Create 'send' command.
147 *
148 * @param label name for command.
149 * @return command.
150 */
151struct GNUNET_TESTING_Command 99struct GNUNET_TESTING_Command
152GNUNET_TESTING_DHTU_cmd_send (const char *label) 100GNUNET_TESTING_DHTU_cmd_send (const char *label)
153{ 101{
@@ -160,7 +108,7 @@ GNUNET_TESTING_DHTU_cmd_send (const char *label)
160 .cls = ss, 108 .cls = ss,
161 .label = label, 109 .label = label,
162 .run = &send_run, 110 .run = &send_run,
163 .finish = &send_finish, 111 .ac = &ss->ac,
164 .cleanup = &send_cleanup, 112 .cleanup = &send_cleanup,
165 .traits = &send_traits 113 .traits = &send_traits
166 }; 114 };