diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-02-06 12:22:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-02-06 12:22:33 +0000 |
commit | 2a37056aa302c9534dc0da3101e3065bd0c1df48 (patch) | |
tree | f21c30c827aa7c6c7a83b560d1ae5e5535a7a24e /src | |
parent | d94d7fbcc89a3a61db7bbd87e2cd809c2cc1a623 (diff) | |
download | gnunet-2a37056aa302c9534dc0da3101e3065bd0c1df48.tar.gz gnunet-2a37056aa302c9534dc0da3101e3065bd0c1df48.zip |
indent
Diffstat (limited to 'src')
-rw-r--r-- | src/arm/test_exponential_backoff.c | 139 |
1 files changed, 76 insertions, 63 deletions
diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index 49092dc42..8f7017b77 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.c | |||
@@ -61,7 +61,8 @@ do_nothing_notify (void *cls, int success) | |||
61 | { | 61 | { |
62 | GNUNET_assert (success == GNUNET_YES); | 62 | GNUNET_assert (success == GNUNET_YES); |
63 | ok = 1; | 63 | ok = 1; |
64 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL); | 64 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_SECONDS, |
65 | &kill_task, NULL); | ||
65 | } | 66 | } |
66 | 67 | ||
67 | 68 | ||
@@ -69,7 +70,9 @@ static void | |||
69 | arm_notify (void *cls, int success) | 70 | arm_notify (void *cls, int success) |
70 | { | 71 | { |
71 | GNUNET_assert (success == GNUNET_YES); | 72 | GNUNET_assert (success == GNUNET_YES); |
72 | GNUNET_ARM_start_service (arm, "do-nothing", TIMEOUT, &do_nothing_notify, NULL); | 73 | GNUNET_ARM_start_service (arm, |
74 | "do-nothing", TIMEOUT, | ||
75 | &do_nothing_notify, NULL); | ||
73 | } | 76 | } |
74 | 77 | ||
75 | 78 | ||
@@ -80,33 +83,39 @@ kill_task (void *cbData, | |||
80 | 83 | ||
81 | static void | 84 | static void |
82 | do_nothing_restarted_notify_task (void *cls, | 85 | do_nothing_restarted_notify_task (void *cls, |
83 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 86 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
84 | { | 87 | { |
85 | static char a; | 88 | static char a; |
86 | static int trialCount = 0; | 89 | static int trialCount = 0; |
87 | 90 | ||
88 | trialCount++; | 91 | trialCount++; |
89 | 92 | ||
90 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) { | 93 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) { |
91 | fprintf(killLogFilePtr, "%d.Reason is shutdown!\n", trialCount); | 94 | fprintf(killLogFilePtr, |
92 | } | 95 | "%d.Reason is shutdown!\n", |
93 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) { | 96 | trialCount); |
94 | fprintf(killLogFilePtr, "%d.Reason is timeout!\n", trialCount); | 97 | } |
95 | } | 98 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) { |
96 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0) { | 99 | fprintf(killLogFilePtr, |
97 | fprintf(killLogFilePtr, "%d.Service is running!\n", trialCount); | 100 | "%d.Reason is timeout!\n", |
98 | } | 101 | trialCount); |
99 | 102 | } | |
100 | GNUNET_SCHEDULER_add_now (sched, &kill_task, &a); | 103 | else if ((tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE) != 0) { |
104 | fprintf(killLogFilePtr, | ||
105 | "%d.Service is running!\n", | ||
106 | trialCount); | ||
107 | } | ||
108 | GNUNET_SCHEDULER_add_now (sched, &kill_task, &a); | ||
101 | } | 109 | } |
102 | 110 | ||
103 | 111 | ||
104 | static void | 112 | static void |
105 | do_test (void *cbData, | 113 | do_test (void *cbData, |
106 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 114 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
107 | { | 115 | { |
108 | GNUNET_CLIENT_service_test(sched, "do-nothing", cfg, TIMEOUT, | 116 | GNUNET_CLIENT_service_test(sched, "do-nothing", |
109 | &do_nothing_restarted_notify_task, NULL); | 117 | cfg, TIMEOUT, |
118 | &do_nothing_restarted_notify_task, NULL); | ||
110 | } | 119 | } |
111 | 120 | ||
112 | 121 | ||
@@ -114,37 +123,42 @@ static void | |||
114 | kill_task (void *cbData, | 123 | kill_task (void *cbData, |
115 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 124 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
116 | { | 125 | { |
117 | static struct GNUNET_CLIENT_Connection * doNothingConnection = NULL; | 126 | static struct GNUNET_CLIENT_Connection * doNothingConnection = NULL; |
118 | static struct GNUNET_TIME_Absolute startedWaitingAt; | 127 | static struct GNUNET_TIME_Absolute startedWaitingAt; |
119 | struct GNUNET_TIME_Relative waitedFor; | 128 | struct GNUNET_TIME_Relative waitedFor; |
120 | static int trialCount = 0; | 129 | static int trialCount = 0; |
121 | 130 | ||
122 | if (NULL != cbData) { | 131 | if (NULL != cbData) { |
123 | waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt); | 132 | waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt); |
124 | fprintf(killLogFilePtr, "Waited for: %llu milliseconds\n\n", | 133 | fprintf(killLogFilePtr, |
125 | (unsigned long long) waitedFor.value); | 134 | "Waited for: %llu ms\n\n", |
126 | } | 135 | (unsigned long long) waitedFor.value); |
127 | /* Connect to the doNothing task */ | 136 | } |
128 | doNothingConnection = GNUNET_CLIENT_connect (sched, "do-nothing", cfg); | 137 | /* Connect to the doNothing task */ |
129 | if (NULL == doNothingConnection) | 138 | doNothingConnection = GNUNET_CLIENT_connect (sched, "do-nothing", cfg); |
130 | fprintf(killLogFilePtr, "Unable to connect to do-nothing process!\n"); | 139 | if (NULL == doNothingConnection) |
131 | 140 | fprintf(killLogFilePtr, | |
132 | if (trialCount == 12) { | 141 | "Unable to connect to do-nothing process!\n"); |
133 | GNUNET_ARM_stop_service (arm, "do-nothing", TIMEOUT, &arm_notify_stop, NULL); | 142 | |
134 | ok = 0; | 143 | if (trialCount == 12) { |
135 | return; | 144 | GNUNET_ARM_stop_service (arm, |
136 | } | 145 | "do-nothing", |
137 | 146 | TIMEOUT, | |
138 | /* Use the created connection to kill the doNothingTask */ | 147 | &arm_notify_stop, NULL); |
139 | GNUNET_CLIENT_service_shutdown(doNothingConnection); | 148 | ok = 0; |
140 | trialCount++; | 149 | return; |
141 | if (startedWaitingAt.value == 0) | 150 | } |
142 | waitedFor.value = 0; | 151 | |
143 | startedWaitingAt = GNUNET_TIME_absolute_get(); | 152 | /* Use the created connection to kill the doNothingTask */ |
144 | GNUNET_SCHEDULER_add_delayed (sched, | 153 | GNUNET_CLIENT_service_shutdown(doNothingConnection); |
145 | waitedFor, | 154 | trialCount++; |
146 | &do_test, | 155 | if (startedWaitingAt.value == 0) |
147 | NULL); | 156 | waitedFor.value = 0; |
157 | startedWaitingAt = GNUNET_TIME_absolute_get(); | ||
158 | GNUNET_SCHEDULER_add_delayed (sched, | ||
159 | waitedFor, | ||
160 | &do_test, | ||
161 | NULL); | ||
148 | } | 162 | } |
149 | 163 | ||
150 | 164 | ||
@@ -195,22 +209,21 @@ check () | |||
195 | static int | 209 | static int |
196 | init() | 210 | init() |
197 | { | 211 | { |
198 | killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log"); | 212 | killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log"); |
199 | if (NULL == (killLogFilePtr = FOPEN(killLogFileName, "w"))) { | 213 | if (NULL == (killLogFilePtr = FOPEN(killLogFileName, "w"))) { |
200 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", killLogFileName); | 214 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", killLogFileName); |
201 | GNUNET_free (killLogFileName); | 215 | GNUNET_free (killLogFileName); |
202 | return GNUNET_SYSERR; | 216 | return GNUNET_SYSERR; |
203 | } | 217 | } |
204 | 218 | return GNUNET_OK; | |
205 | return GNUNET_OK; | ||
206 | } | 219 | } |
207 | 220 | ||
208 | 221 | ||
209 | static void | 222 | static void |
210 | houseKeep() | 223 | houseKeep() |
211 | { | 224 | { |
212 | GNUNET_assert (0 == fclose (killLogFilePtr)); | 225 | GNUNET_assert (0 == fclose (killLogFilePtr)); |
213 | GNUNET_free(killLogFileName); | 226 | GNUNET_free(killLogFileName); |
214 | } | 227 | } |
215 | 228 | ||
216 | 229 | ||