aboutsummaryrefslogtreecommitdiff
path: root/src/arm/arm_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/arm_api.c')
-rw-r--r--src/arm/arm_api.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index dda5561ac..fb4f3a02d 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -66,6 +66,7 @@ struct ShutdownContext
66 * Scheduler to be used to call continuation 66 * Scheduler to be used to call continuation
67 */ 67 */
68 struct GNUNET_SCHEDULER_Handle *sched; 68 struct GNUNET_SCHEDULER_Handle *sched;
69
69 /** 70 /**
70 * Connection to the service that is being shutdown. 71 * Connection to the service that is being shutdown.
71 */ 72 */
@@ -79,7 +80,7 @@ struct ShutdownContext
79 /** 80 /**
80 * Task set up to cancel the shutdown request on timeout. 81 * Task set up to cancel the shutdown request on timeout.
81 */ 82 */
82 GNUNET_SCHEDULER_TaskIdentifier cancel_task; 83 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
83 84
84 /** 85 /**
85 * Task to call once shutdown complete 86 * Task to call once shutdown complete
@@ -98,6 +99,7 @@ struct ShutdownContext
98 99
99}; 100};
100 101
102
101/** 103/**
102 * Handler receiving response to service shutdown requests. 104 * Handler receiving response to service shutdown requests.
103 * First call with NULL: service misbehaving, or something. 105 * First call with NULL: service misbehaving, or something.
@@ -110,7 +112,8 @@ struct ShutdownContext
110 * @param msg NULL, indicating socket closure. 112 * @param msg NULL, indicating socket closure.
111 */ 113 */
112static void 114static void
113service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg) 115service_shutdown_handler (void *cls,
116 const struct GNUNET_MessageHeader *msg)
114{ 117{
115 struct ShutdownContext *shutdown_ctx = cls; 118 struct ShutdownContext *shutdown_ctx = cls;
116 119
@@ -121,7 +124,7 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
121 "Service handle shutdown before ACK!\n"); 124 "Service handle shutdown before ACK!\n");
122 if (shutdown_ctx->cont != NULL) 125 if (shutdown_ctx->cont != NULL)
123 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); 126 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
124 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task); 127 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->timeout_task);
125 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 128 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
126 GNUNET_free(shutdown_ctx); 129 GNUNET_free(shutdown_ctx);
127 } 130 }
@@ -134,7 +137,7 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
134 if (shutdown_ctx->cont != NULL) 137 if (shutdown_ctx->cont != NULL)
135 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO); 138 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_NO);
136 139
137 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task); 140 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->timeout_task);
138 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 141 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
139 GNUNET_free(shutdown_ctx); 142 GNUNET_free(shutdown_ctx);
140 } 143 }
@@ -162,7 +165,7 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
162 if (shutdown_ctx->cont != NULL) 165 if (shutdown_ctx->cont != NULL)
163 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES); 166 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_YES);
164 167
165 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->cancel_task); 168 GNUNET_SCHEDULER_cancel(shutdown_ctx->sched, shutdown_ctx->timeout_task);
166 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 169 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
167 GNUNET_free(shutdown_ctx); 170 GNUNET_free(shutdown_ctx);
168 break; 171 break;
@@ -170,17 +173,21 @@ service_shutdown_handler (void *cls, const struct GNUNET_MessageHeader *msg)
170 } 173 }
171} 174}
172 175
176
173/** 177/**
174 * Shutting down took too long, cancel receive and return error. 178 * Shutting down took too long, cancel receive and return error.
175 * 179 *
176 * @param cls closure 180 * @param cls closure
177 * @param tc context information (why was this task triggered now) 181 * @param tc context information (why was this task triggered now)
178 */ 182 */
179void service_shutdown_cancel (void *cls, 183static void
180 const struct GNUNET_SCHEDULER_TaskContext * tc) 184service_shutdown_timeout (void *cls,
185 const struct GNUNET_SCHEDULER_TaskContext * tc)
181{ 186{
182 struct ShutdownContext *shutdown_ctx = cls; 187 struct ShutdownContext *shutdown_ctx = cls;
183 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "service_shutdown_cancel called!\n"); 188
189 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
190 _("Timeout during attempt to shutdown service. Hoping it is simply down already.\n"));
184 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR); 191 shutdown_ctx->cont(shutdown_ctx->cont_cls, GNUNET_SYSERR);
185 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO); 192 GNUNET_CLIENT_disconnect (shutdown_ctx->sock, GNUNET_NO);
186 GNUNET_free(shutdown_ctx); 193 GNUNET_free(shutdown_ctx);
@@ -215,10 +222,10 @@ write_shutdown (void *cls, size_t size, void *buf)
215 GNUNET_CLIENT_receive (shutdown_ctx->sock, 222 GNUNET_CLIENT_receive (shutdown_ctx->sock,
216 &service_shutdown_handler, shutdown_ctx, 223 &service_shutdown_handler, shutdown_ctx,
217 GNUNET_TIME_UNIT_FOREVER_REL); 224 GNUNET_TIME_UNIT_FOREVER_REL);
218 shutdown_ctx->cancel_task = GNUNET_SCHEDULER_add_delayed (shutdown_ctx->sched, 225 shutdown_ctx->timeout_task = GNUNET_SCHEDULER_add_delayed (shutdown_ctx->sched,
219 GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout), 226 GNUNET_TIME_absolute_get_remaining(shutdown_ctx->timeout),
220 &service_shutdown_cancel, 227 &service_shutdown_timeout,
221 shutdown_ctx); 228 shutdown_ctx);
222 msg = (struct GNUNET_MessageHeader *) buf; 229 msg = (struct GNUNET_MessageHeader *) buf;
223 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN); 230 msg->type = htons (GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN);
224 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 231 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
@@ -248,6 +255,7 @@ arm_service_shutdown (struct GNUNET_SCHEDULER_Handle *sched,
248 void *cont_cls) 255 void *cont_cls)
249{ 256{
250 struct ShutdownContext *shutdown_ctx; 257 struct ShutdownContext *shutdown_ctx;
258
251 shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext)); 259 shutdown_ctx = GNUNET_malloc(sizeof(struct ShutdownContext));
252 shutdown_ctx->sched = sched; 260 shutdown_ctx->sched = sched;
253 shutdown_ctx->cont = cont; 261 shutdown_ctx->cont = cont;
@@ -633,6 +641,7 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
633 struct RequestContext *sctx; 641 struct RequestContext *sctx;
634 struct GNUNET_CLIENT_Connection *client; 642 struct GNUNET_CLIENT_Connection *client;
635 size_t slen; 643 size_t slen;
644
636#if DEBUG_ARM 645#if DEBUG_ARM
637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
638 _("Asked to start service `%s' within %llu ms\n"), service_name, 647 _("Asked to start service `%s' within %llu ms\n"), service_name,