free(request);
}
+static int _dp_client_can_remove_request(dp_request_fmt *request)
+{
+ if (request->id <= 0 || request->state == DP_STATE_NONE) {
+ TRACE_ERROR("id:%d unexpected request.", request->id);
+ return 1;
+ }
+
+ int now_time = (int)time(NULL);
+ if (request->access_time > 0 &&
+ (now_time - request->access_time) > DP_CARE_CLIENT_CLEAR_INTERVAL) {
+ // check accesstime. if difference is bigger than DP_CARE_CLIENT_CLEAR_INTERVAL, clear.
+ if (request->state == DP_STATE_READY || request->state == DP_STATE_COMPLETED ||
+ request->state == DP_STATE_CANCELED || request->state == DP_STATE_FAILED)
+ return 1;
+ }
+
+ if (request->state == DP_STATE_PAUSED &&
+ dp_is_alive_download(request->agent_id) == 0) {
+ // paused & agent_id not exist.... unload from memory.
+ TRACE_ERROR("id:%d hanged as paused (%d/%d)",request->id, request->access_time, now_time);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int _dp_client_check_zombie_request(dp_request_fmt *request)
+{
+ int now_time = (int)time(NULL);
+ int time_diff = 0;
+
+ if (request->access_time > 0)
+ time_diff = now_time - request->access_time;
+
+ if (time_diff > DP_CARE_CLIENT_CLEAR_INTERVAL && request->state == DP_STATE_CONNECTING) {
+ TRACE_ERROR("id:%d connection timeout (%d/%d)",
+ request->id, request->access_time, now_time);
+ return 1;
+ }
+
+ return 0;
+}
+
void dp_client_clear_requests(void *slotp)
{
dp_client_slots_fmt *slot = (dp_client_slots_fmt *)slotp;
TRACE_ERROR("check slot memory");
return ;
}
+
dp_client_fmt *client = &slot->client;
+ dp_request_fmt *tailp = client->requests;
+ dp_request_fmt *prevp = NULL;
- int now_time = (int)time(NULL);
- int i = 0;
unsigned queued_count = 0;
unsigned ongoing_count = 0;
- dp_request_fmt *tailp = client->requests;
- dp_request_fmt *prevp = NULL;
- for (; tailp != NULL; i++) {
- unsigned can_unload = 0;
- if (tailp->id <= 0 || tailp->state == DP_STATE_NONE) {
- TRACE_ERROR("id:%d unexpected request (%d/%d)", tailp->id, tailp->access_time, now_time);
- can_unload = 1;
- } else if (tailp->access_time > 0 &&
- (now_time - tailp->access_time) > DP_CARE_CLIENT_CLEAR_INTERVAL) {
- // check accesstime. if difference is bigger than DP_CARE_CLIENT_CLEAR_INTERVAL, clear.
-
- if (tailp->state == DP_STATE_READY ||
- tailp->state == DP_STATE_COMPLETED ||
- tailp->state == DP_STATE_CANCELED ||
- tailp->state == DP_STATE_FAILED) {
- can_unload = 1;
- } else if (tailp->state == DP_STATE_CONNECTING) { // it take 120 sec over to connect. it means zombie.
- TRACE_ERROR("id:%d connection timeout (%d/%d)", tailp->id, tailp->access_time, now_time);
- if (dp_cancel_agent_download_without_update(tailp->agent_id) < 0)
- TRACE_ERROR("failed to cancel download(%d) id:%d", tailp->agent_id, tailp->id);
- tailp->state = DP_STATE_FAILED;
- tailp->error = DP_ERROR_CONNECTION_TIMED_OUT;
- if (tailp->noti_type == DP_NOTIFICATION_TYPE_COMPLETE_ONLY ||
- tailp->noti_type == DP_NOTIFICATION_TYPE_ALL) {
- if (dp_notification_manager_push_notification(slot, tailp, DP_NOTIFICATION) < 0)
- TRACE_ERROR("failed to register notification for id:%d", tailp->id);
- }
+ for (int i = 0; tailp != NULL; i++) {
+ int can_remove = _dp_client_can_remove_request(tailp);
+ int is_zombie = _dp_client_check_zombie_request(tailp);
+
+ if (is_zombie) {
+ TRACE_ERROR("id:%d is zombie request.", tailp->id);
+ if (dp_cancel_agent_download_without_update(tailp->agent_id) < 0)
+ TRACE_ERROR("failed to cancel download(%d) id:%d", tailp->agent_id, tailp->id);
+ tailp->state = DP_STATE_FAILED;
+ tailp->error = DP_ERROR_CONNECTION_TIMED_OUT;
+ if (tailp->noti_type == DP_NOTIFICATION_TYPE_COMPLETE_ONLY ||
+ tailp->noti_type == DP_NOTIFICATION_TYPE_ALL) {
+ if (dp_notification_manager_push_notification(slot, tailp, DP_NOTIFICATION) < 0)
+ TRACE_ERROR("failed to register notification for id:%d", tailp->id);
}
- } else if (tailp->state == DP_STATE_PAUSED &&
- dp_is_alive_download(tailp->agent_id) == 0) {
- // paused & agent_id not exist.... unload from memory.
- TRACE_ERROR("id:%d hanged as paused (%d/%d)", tailp->id, tailp->access_time, now_time);
- can_unload = 1;
}
- if (can_unload == 1) {
+ if (can_remove) {
dp_request_fmt *removep = tailp;
if (prevp == NULL) // first request.
client->requests = tailp->next;