1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*
*
* Stuff that slows the transmission of jobs to PostScript printers. ONLY use it
* if you appear to be having trouble with flow control. The idea is simple - only
* send a significant amount of data when we're certain the printer is in the
* WAITING state. Depends on receiving status messages and only works when the
* program is run as a single process. What's done should stop printer generated
* XOFFs - provided our input buffer (ie. blocksize) is sufficiently small. Was
* originally included in the postio.tmp directory, but can now be requested with
* the -S option. Considered eliminating this code, but some printers still depend
* on it. In particular Datakit connections made using Datakit PVCs and DACUs seem
* to have the most problems. Much of the new stuff that was added can't work when
* you use this code and will be automatically disabled.
*
*/
#include <stdio.h>
#include "gen.h"
#include "postio.h"
extern char *block;
extern int blocksize;
extern int head;
extern int tail;
extern char *line;
extern char mesg[];
extern int ttyo;
/*****************************************************************************/
slowsend(fd_in)
int fd_in; /* next input file */
{
/*
*
* A slow version of send() that's very careful about when data is sent to the
* printer. Should help prevent overflowing the printer's input buffer, provided
* blocksize is sufficiently small (1024 should be safe). It's a totally kludged
* up routine that should ONLY be used if you have constant transmission problems.
* There's really no way it will be able to drive a printer much faster that about
* six pages a minute, even for the simplest jobs. Get it by using the -S option.
*
*/
while ( readblock(fd_in) )
switch ( getstatus(0) ) {
case WAITING:
writeblock(blocksize);
break;
case BUSY:
case IDLE:
case PRINTING:
writeblock(30);
break;
case NOSTATUS:
case UNKNOWN:
break;
case PRINTERERROR:
sleep(30);
break;
case ERROR:
fprintf(stderr, "%s", mesg); /* for csw */
error(FATAL, "PostScript Error");
break;
case FLUSHING:
error(FATAL, "Flushing Job");
break;
case DISCONNECT:
error(FATAL, "Disconnected - printer may be offline");
break;
default:
sleep(2);
break;
} /* End switch */
} /* End of send */
/*****************************************************************************/
static writeblock(num)
int num; /* most bytes we'll write */
{
int count; /* bytes successfully written */
/*
*
* Called from send() when it's OK to send the next block to the printer. head
* is adjusted after the write, and the number of bytes that were successfully
* written is returned to the caller.
*
*/
if ( num > tail - head )
num = tail - head;
if ( (count = write(ttyo, &block[head], num)) == -1 )
error(FATAL, "error writing to %s", line);
else if ( count == 0 )
error(FATAL, "printer appears to be offline");
head += count;
return(count);
} /* End of writeblock */
/*****************************************************************************/
|