ptg10805159
812 Communicating with a Network Printer Chapter 21
1/*
2*Print server daemon.
3*/
4#include "apue.h"
5#include <fcntl.h>
6#include <dirent.h>
7#include <ctype.h>
8#include <pwd.h>
9#include <pthread.h>
10 #include <strings.h>
11 #include <sys/select.h>
12 #include <sys/uio.h>
13 #include "print.h"
14 #include "ipp.h"
15 /*
16 * These are for the HTTP response from the printer.
17 */
18 #define HTTP_INFO(x) ((x) >= 100 && (x) <= 199)
19 #define HTTP_SUCCESS(x) ((x) >= 200 && (x) <= 299)
20 /*
21 * Describes a print job.
22 */
23 struct job {
24 struct job *next; /* next in list */
25 struct job *prev; /* previous in list */
26 int32_t jobid; /* job ID */
27 struct printreq req; /* copy of print request */
28 };
29 /*
30 * Describes a thread processing a client request.
31 */
32 struct worker_thread {
33 struct worker_thread *next; /* next in list */
34 struct worker_thread *prev; /* previous in list */
35 pthread_t tid; /* thread ID */
36 int sockfd; /* socket */
37 };
[1 – 19] The printer spooling daemon includes the IPP header file that we saw earlier,
because the daemon needs to communicate with the printer using this
protocol. TheHTTP_INFOandHTTP_SUCCESSmacros define the status of the
HTTP request (recall that IPP is built on top of HTTP). Section 10 in RFC 2616
defines the HTTP status codes.
[20 – 37] Thejobandworker_threadstructures areused by the spooling daemon to
keep track of print jobs and threads accepting print requests, respectively.