From 1ac18054c1810bebb4a067e93f366173f87f7adb Mon Sep 17 00:00:00 2001 From: lemoer Date: Sat, 13 Aug 2016 17:04:01 +0200 Subject: [PATCH] respondd: request_task is now created outside schedule_push_request() --- net/respondd/src/respondd.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/net/respondd/src/respondd.c b/net/respondd/src/respondd.c index 7f939d8..2f0efa8 100644 --- a/net/respondd/src/respondd.c +++ b/net/respondd/src/respondd.c @@ -183,20 +183,11 @@ static const struct respondd_provider_info * get_providers(const char *filename) return ret; } -bool schedule_push_request(struct request_schedule *s, char* req, - struct sockaddr *addr, socklen_t addrlen, - int64_t scheduled_time) { +bool schedule_push_request(struct request_schedule *s, struct request_task *new_task) { if (s->length >= SCHEDULE_LEN) // schedule is full return false; - struct request_task *new_task = malloc(sizeof(struct request_task)); - // store the request - new_task->scheduled_time = scheduled_time; - strcpy(new_task->request, req); - memcpy(&new_task->client_addr, addr, addrlen); - new_task->client_addrlen = addrlen; - if (!s->list_head || s->list_head->scheduled_time > new_task->scheduled_time) { new_task->next = s->list_head; s->list_head = new_task; @@ -458,15 +449,26 @@ static bool accept_request(struct request_schedule *schedule, int sock, input[input_bytes] = 0; // only multicast requests are delayed + update_time(); int64_t delay; if (IN6_IS_ADDR_MULTICAST(&destaddr)) { - update_time(); delay = rand() % max_multicast_delay; } else { delay = 0; } - schedule_push_request(schedule, input, (struct sockaddr *)&addr, addrlen, now + delay); + struct request_task *new_task = malloc(sizeof(struct request_task)); + new_task->scheduled_time = now + delay; + strcpy(new_task->request, input); + memcpy(&new_task->client_addr, &addr, addrlen); + new_task->client_addrlen = addrlen; + + + if(!schedule_push_request(schedule, new_task)) { + free(new_task); + return false; + } + return true; }