static void empty_unit(int chassis, int geoslot) { unit_t *u = &units[chassis][geoslot]; empty_unit_iface(u); if (u->imsg) { /* then if an inbound message buffer exists */ u->imsg = (char *)realloc(u->imsg, 1); /* and re-allocate the old large buffer into a new small one */ if (u->imsg == NULL) { /* oops, realloc call failed */ fprintf(stderr, "Warning...call to realloc() failed, value of errno is %d\n", errno); } } static void empty_unit_table(void) { int chassis, geoslot; for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) { for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) { if (units[chassis][geoslot].ip != NULL) { free(units[chassis][geoslot].ip); /* get rid of the malloc'ed space that holds the IP address */ units[chassis][geoslot].ip = 0; /* then set the pointer to NULL */ } empty_unit(chassis, geoslot); } } }
static void empty_unit_table(void) { int chassis, geoslot; for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) { for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) { if (units[chassis][geoslot].ip != NULL) { free(units[chassis][geoslot].ip); /* get rid of the malloc'ed space that holds the IP address */ units[chassis][geoslot].ip = 0; /* then set the pointer to NULL */ } empty_unit(chassis, geoslot); } } }
static void send_to_fd(int fd, int len, unsigned char *str) { int nwritten; int chassis, geoslot; while (len > 0) { if ((nwritten = write(fd, str, len)) <= 0) { find_unit_by_fd(fd, &chassis, &geoslot, NULL); if (units[chassis][geoslot].fd == fd) close_with_IOP(chassis, geoslot, LIVE); else if (units[chassis][geoslot].find_fd == fd) close_with_IOP(chassis, geoslot, FIND); empty_unit(chassis, geoslot); return; } len -= nwritten; str += nwritten; } }