void destroy_single_rcb(rcb_t *rcb) { assert(rcb); if(rcb->buffer) { free(rcb->buffer); } if(rcb->have_peers) { destroy_darr(rcb->have_peers); } if(rcb->pd_get) free(rcb->pd_get); free(rcb); }
int is_pd_req_timeout(rcb_t *rcb, long elapsed) { if(rcb->left_time > elapsed) { rcb->left_time -= elapsed; } else { // reset time out dbg_print(2, "pd req timeout\n"); rcb->left_time = PD_RCB_TIMEOUT; if(rcb->have_peers) { destroy_darr(rcb->have_peers); rcb->have_peers = NULL; } return 1; } return 0; }
int main(void) { DARR_T *me; int id[] = {3,2,1,8,9,7}; int i; struct stu_st tmp; int num; me = init_darr(sizeof(struct stu_st)); if (me == NULL) { exit(1); } for (i = 0; i < sizeof(id) / sizeof(*id); i++) { tmp.id = id[i]; snprintf(tmp.name, NAMESIZE, "bendan%d", id[i]); tmp.score = 100-id[i]; insert_darr(me, &tmp); } traval_darr(me, print_arr); printf("\n\n"); #if 0 num = 8; delete_darr(me, &num, id_cmp); delete_darr(me, "bendan1", name_cmp); traval_darr(me, print_arr); #endif if (search_darr(me, "bendan7", &tmp, name_cmp) < 0) { printf("not found\n"); } else { printf("find it: %d %s\n", tmp.id, tmp.name); } destroy_darr(me); return 0; }