int commSayBye( commSayByeReq_t * req, // Request commSayByeResp_t * resp) // Response (or NULL) { commSayByeResp_t respDummy; trump_hdl_t h; comm_status_t err; int err0; DPRINT(("@TRUMP commSayBye(): ")); if (resp == NULL) resp = &respDummy; if (req == NULL) { resp->status = 1; return FALSE; } h = commHdl2trump(req->player); err0 = assoctab_subscript_delete(peertab, h); err = tcpabi_udp_close(h, UDP_CLOSE_NORMAL); DPRINT(("commSayBye: player %d, hdl %d, delete returns %d, tcpabi_udp_close returns %d\n", req->player, h, err0, err)); if (err != TCPABI_NO_ERROR) { DPRINT(("commSayBye: tcpabi_udp_close returns %d\n", err)); resp->status = 2; return FALSE; } resp->status = 0; return (TRUE); }
/*-------------------------------------------------------------------------- Delete a particular player from the table. --------------------------------------------------------------------------*/ dp_result_t pv_deletePlayer(pv_t *pv, int player) { int i; pv_peer_t *peer; if (!pv) return dp_RES_BUG; DPRINT(("pv_deletePlayer(dp, %d)\n", player)); /* Get this player's table. */ peer = (pv_peer_t *)assoctab_subscript(pv->peers, player); if (!peer) { DPRINT(("pv_deletePlayer: no table for player %d\n", player)); return dp_RES_EMPTY; } /* Free all memory pointed to by the variables in peer->vars */ for (i=0; i < peer->vars->n_used; i++) { pv_var_t *pvar; assoctab_item_t *pe; pe = assoctab_getkey(peer->vars, i); if (!pe) break; /* horrible error */ pvar = (pv_var_t *) &pe->value; /* Destroy their values */ if (pvar->buf) dp_FREE(pvar->buf); } if (peer->incoming.buf) dp_FREE(peer->incoming.buf); /* Destroy it, and remove it from the table. */ assoctab_destroy(peer->vars); if (assoctab_subscript_delete(pv->peers, player)) return dp_RES_BUG; return dp_RES_OK; }
/*------------------------------------------------------------------------ Clean up any data associated with the given handle. ------------------------------------------------------------------------*/ static void sbdserv_handleClosed(sbdserv_t *sbdserv, int h) { if (!sbdserv || (h == -1)) { DPRINT(("sbdserv_handleClosed: bad params (h:%d)\n", h)); return; } if (assoctab_subscript_delete(sbdserv->conns, h)) { DPRINT(("sbdserv_handleClosed: no such handle h:%d\n", h)); return; } FD_CLR(h, &sbdserv->fds); if (h == sbdserv->sockmax) for (sbdserv->sockmax--; sbdserv->sockmax >= 0; sbdserv->sockmax--) if (FD_ISSET(sbdserv->sockmax, &sbdserv->fds) || (sbdserv->sockmax == sbdserv->sockin)) break; DPRINT(("sbdserv_handleClosed(h:%d)\n", h)); }
/*------------------------------------------------------------------------ Clean up any data associated with the given handle. ------------------------------------------------------------------------*/ static void bhttp_handleClosed(bhttp_t *bhttp, int h) { if (!bhttp || (h == -1)) { DPRINT(("bhttp_handleClosed: bad params (h:%d)\n", h)); return; } if (assoctab_subscript_delete(bhttp->conns, h)) { DPRINT(("bhttp_handleClosed: no such handle h:%d\n", h)); return; } FD_CLR(h, &bhttp->rfds); FD_CLR(h, &bhttp->wfds); if (h == bhttp->sockmax) for (bhttp->sockmax--; bhttp->sockmax >= 0; bhttp->sockmax--) if (FD_ISSET(bhttp->sockmax, &bhttp->rfds) || FD_ISSET(bhttp->sockmax, &bhttp->wfds) || (bhttp->sockmax == bhttp->sockin)) break; DPRINT(("bhttp_handleClosed(h:%d)\n", h)); }
void test1(assoctab_t *pt, int callnum) { int i; int errs; int *p; /* Try to delete something that's not there */ if (assoctab_subscript_delete(pt, 0) == 0) { printf("delete0: test failed\n"); exit(1); } /* Fill it up */ for (i=32; i>=0; i--) { p = assoctab_subscript_grow(pt, i); if (p == NULL) { printf("grow1: test failed on i=%d\n", i); exit(1); } if (*p != 0) { printf("initial value test: test failed, i %d, *p %d\n", i, *p); errs++; } *p = i; printf("."); } /* Make sure it got filled up right */ for (i=0; i<33; i++) { p = assoctab_subscript(pt, i); if (p == NULL) { printf("subscript2: test failed\n"); exit(1); } if (*p != i) { printf("value test: test failed\n"); exit(1); } } /* Make sure it's empty past the end */ if (assoctab_subscript(pt, i) != NULL) { printf("subscript3: test failed\n"); exit(1); } /* Delete halfway thru the table */ if (assoctab_subscript_delete(pt, 16)) { printf("delete1: test failed\n"); exit(1); } /* Verify that rest of table still there */ errs = 0; for (i=0; i<33; i++) { p = assoctab_subscript(pt, i); if (i == 16) { if (p != NULL) { printf("subscript5: test failed, i %d: expected null, got %p, %d\n", i, p, *p); errs ++; } } else { if (p == NULL) { printf("subscript5: test failed, i %d, got p NULL\n", i); errs ++; } if (*p != i) { printf("value test 2: test failed, i %d. Expected %d, got %d\n", i, i, *p); errs ++; } } } /* Delete elements, get ready for next run */ for (i=0; i<33; i++) { int b; b = assoctab_subscript_delete(pt, i); if (b ^ (i == 16)) { printf("delete2: test failed, i %d. Expected %d, got %d\n", i==16, b); errs ++; } } if (pt->n_used != 0) { printf("delete3: test failed. Expected n_used = zero, got %d\n", pt->n_used); errs ++; } if (errs) { printf("test: failed on call %d\n", callnum); exit(1); } }