ptg10805159
Section 21.5 Source Code 837
754 if (nr < 0) {
755 log_ret("can’t read %s", name);
756 goto defer;
757 }
758 /*
759 * Read the response from the printer.
760 */
761 if (printer_status(sockfd, jp)) {
762 unlink(name);
763 sprintf(name, "%s/%s/%d", SPOOLDIR, REQDIR, jp->jobid);
764 unlink(name);
765 free(jp);
766 jp =NULL;
767 }
768 defer:
769 close(fd);
770 if (sockfd >= 0)
771 close(sockfd);
772 if (jp != NULL) {
773 replace_job(jp);
774 nanosleep(&ts, NULL);
775 }
776 }
777 }
778 /*
779 * Read data from the printer, possibly increasing the buffer.
780 * Returns offset of end of data in buffer or -1 on failure.
781 *
782 * LOCKING: none.
783 */
784 ssize_t
785 readmore(int sockfd, char **bpp, int off, int *bszp)
[754 – 757] When we reach the end of the file,readwill return 0. However,ifread
fails, we log an error message and jump todefer.
[758 – 767] After sending the file to the printer, we callprinter_statusto read the
printer ’sresponse to our request. On success,printer_statusreturns a
nonzerovalue and we delete the data and control files. Then we free the
jobstructure, set its pointer toNULL,and fall through to thedeferlabel.
[768 – 777] At thedeferlabel, we close the file descriptor for the open data file. If the
socket descriptor is valid, we close it. On error,jpwill point to the job
structurefor the job we aretrying to print, so we place the job back on the
head of the pending job list and delay for 1 minute. On success,jpisNULL,
so we simply go back to the top of the loop to get the next job to print.
[778 – 785] Thereadmorefunction is used to read part of the response message from
the printer.