Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

814 Communicating with a Network Printer Chapter 21


60 int32_t nextjob;
61 pthread_mutex_t joblock = PTHREAD_MUTEX_INITIALIZER;
62 pthread_cond_t jobwait = PTHREAD_COND_INITIALIZER;
63 /*
64 * Function prototypes.
65 */
66 void init_request(void);
67 void init_printer(void);
68 void update_jobno(void);
69 int32_t get_newjobno(void);
70 void add_job(struct printreq *, int32_t);
71 void replace_job(struct job *);
72 void remove_job(struct job *);
73 void build_qonstart(void);
74 void *client_thread(void *);
75 void *printer_thread(void *);
76 void *signal_thread(void *);
77 ssize_t readmore(int, char **, int, int *);
78 int printer_status(int, struct job *);
79 void add_worker(pthread_t, int);
80 void kill_workers(void);
81 void client_cleanup(void *);
82 /*
83 * Main print server thread. Accepts connect requests from
84 * clients and spawns additional threads to service requests.
85 *
86 * LOCKING: none.
87 */
88 int
89 main(int argc, char *argv[])
90 {
91 pthread_t tid;
92 struct addrinfo *ailist, *aip;
93 int sockfd, err, i, n, maxfd;
94 char *host;
95 fd_set rendezvous, rset;
96 struct sigaction sa;
97 struct passwd *pwdp;

[60 – 62] nextjobis the ID of the next print job to be received. Thejoblockmutex
protects the linked list of jobs, as well as the condition represented by the
jobwaitcondition variable.
[63 – 81] We declarethe function prototypes for the remaining functions in this file.
Doing this up front allows us to place the functions in the file without
worrying about the order in which each is called.
[82 – 97] Themainfunction for the printer spooling daemon has two tasks to perform:
initialize the daemon and then process connect requests from clients.
Free download pdf