# keep trying to close socket until we succeed while (close(soc) < 0) { if (errno != EINTR) { # wasn't interrupted, this is some other failure, bail! perror("close"); exit 1; } }