Its purpose is to clean out and remove one element in the array. It may be called as many times as the array has elements. Enjoy.
(I mangled it just a little to make the kind of work we do less obvious. I may be disclosing trade secrets here :) )
void
clear_poll_objects(int iObjToClear)
{
int i, ret_code;
struct pollObject *poll, *tmp_object, *sub_object;
Log(LOG_INFO, "MISC/DEL_POLLOBJ", "d", iObjToClear);
/* ------------------------------------------------------- */
/* walk through each target list to delete all pollObjects */
/* ------------------------------------------------------- */
for(i=iObjToClear; i<= iObjToClear; i++) {
\tpoll= listHeads[i].nextObject;
\twhile(poll!= (struct pollObject *) NULL) {
\t /* --------------------------- */
\t /* loop through all subObjects */
\t /* --------------------------- */
\t sub_object= poll;
\t poll= poll->nextObject; /* for the next iteration. Do not use
\t\t\t\t poll until the end of outer wile()! */
\t while(sub_object!= NULL) {
\t /* ----------------------------------------------- */
\t /* delete the shared part if there are no other references */
\t /* ----------------------------------------------- */
\t if(--sub_object->object->useCount == 0) {
\t\tif((ret_code= rm_shared(sub_object->object)) < 0) {
\t\t listHeads[i].stats.localErr++;
\t\t Log(LOG_ERROR, "ERRORS/FREE_FAIL", "s", "clear_poll_objects");
\t\t};
\t } else
\t\tNLog(LOG_DETAIL, "MISC/DEL_POLLOBJ_SKIP");
\t /* maybelas would delete the malloc'd values here if I did that*/
\t if(sub_object->subObject== NULL) {
\t /* clear out the lastRaw value */\t
\t clearUnivalue(sub_object->lastValue.raw,
\t\t\t sub_object->object->objectType);
\t }
\t /* delete this sub_object */
\t tmp_object= sub_object;
\t sub_object= sub_object->subObject;
\t (void) free(tmp_object);
\t }; /* end loop through sub objects */
};
};\t/* end loop through listHeads */
/* free the listHead struct */
/*free((char *)listHeads);*/
/* ----------------------------------------- */
/* reinitialize the various flags and counts */
/* except those that the cmd line overrides */
/* ----------------------------------------- */
/* for pertarget reconfig just subtract one from the list_count var */
if(list_count >= 0)list_count--;\t/* no valid lists */
/*clear and reallocate the array */
for(i=iObjToClear;i<max_poll_lists;i++)
{
memcpy(&listHeads[i],&listHeads[i+1],sizeof(listHeads[i+1]));
/* free(&listHeads[i+1]);*/
}
if(max_poll_lists > 0)max_poll_lists--;
listHeads = (pollListHead *) realloc(listHeads,sizeof(listHeads[0]) * max_poll_lists);
if(listHeads != NULL)
{
/* sort the new list */
qsort((void*)listHeads,list_count+1,sizeof(listHeads[0]),comparePollHeads);
/* do I really have to do this? there should be no changes at this point */
for(i=0;i<=list_count;i++){
iFoundInArray = AddToArray(listHeads[i].target.inSockAddr.sin_addr.s_addr);
listHeads[i].reqIdMask=(0x1000+ iFoundInArray)<<16;
}
}
else {
NLog(LOG_FATAL, "DSM/BORED");
exit(0);
/* printf("dsm: could not reallocate the listHeads array\\n");*/
}
}