slowsend.c 3.1 KB

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