[X2Go-Commits] [cups-x2go] 03/07: cups-x2go: read data from GS and STDIN in chunks of 8 kbytes, instead of everything at once.

git-admin at x2go.org git-admin at x2go.org
Wed Jun 17 20:15:23 CEST 2015


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository cups-x2go.

commit 6cdc59f5faebca238f9f1aa706a223715dd0a039
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Wed Jun 17 19:22:56 2015 +0200

    cups-x2go: read data from GS and STDIN in chunks of 8 kbytes, instead of everything at once.
    
    Handles large print jobs gracefully.
---
 cups-x2go        |   46 +++++++++++++++++++++++++++++++++++++++-------
 debian/changelog |    2 ++
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/cups-x2go b/cups-x2go
index ec3d813..ae26dd5 100755
--- a/cups-x2go
+++ b/cups-x2go
@@ -25,6 +25,7 @@ use File::Copy;
 use File::Temp qw( tempfile );
 use IPC::Open2;
 use Text::ParseWords;
+use Errno qw( EINTR EIO :POSIX );
 use strict;
 
 openlog($0,'cons,pid','user');
@@ -209,9 +210,25 @@ if (!$psFile)
 	binmode ($tfh, ":raw");
 	binmode (STDIN, ":raw");
 
-	while(<STDIN>)
+	# Get all input from CUPS.
 	{
-		print $tfh $_;
+		# Force readline to not read "lines", but raw data, 8192 bytes at a time.
+		local $/ = \8192;
+
+		while (!eof (STDIN)) {
+			if (defined (my $stdin_data = readline (*STDIN))) {
+				print $tfh $stdin_data;
+			}
+			else {
+				if ($!{EAGAIN} || $!{EWOULDBLOCK} || $!{EINTR}) {
+					continue;
+				}
+				else {
+					syslog ('err', "Error while reading data from stdin: $!\n");
+					die ("Error while reading data from stdin: $!\n");
+				}
+			}
+		}
 	}
 	close $tfh;
 
@@ -240,8 +257,26 @@ binmode ($pdf_fh, ":raw");
 
 close ($gs_in);
 
-# Force readline to not read "lines", but raw data. Get all output from ghostscript.
-my $gs_out_data = do { local $/; readline ($gs_out) };
+# Get all input from GS.
+{
+	# Force readline to not read "lines", but raw data, 8192 bytes at a time.
+	local $/ = \8192;
+
+	while (!eof ($gs_out)) {
+		if (defined (my $gs_out_data = readline ($gs_out))) {
+			print $pdf_fh $gs_out_data;
+		}
+		else {
+			if ($!{EAGAIN} || $!{EWOULDBLOCK} || $!{EINTR}) {
+				continue;
+			}
+			else {
+				syslog ('err', "ERROR: reading data from ps2pdf program failed: $!\n");
+				die ("$0: Error reading data from ps2pdf program failed: $!\n");
+			}
+		}
+	}
+}
 
 close ($gs_out);
 
@@ -274,9 +309,6 @@ if ($conv_fail) {
 
 syslog('debug', "cups-x2go processed postscript file $psFile to $pdfFile");
 
-print $pdf_fh $gs_out_data;
-close ($pdf_fh);
-
 # after we have created the PDF from CUPS's PS file, we can drop the PS file
 unlink ($psFile);
 
diff --git a/debian/changelog b/debian/changelog
index ffba160..2f97415 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -16,6 +16,8 @@ cups-x2go (3.0.1.3-0x2go1) UNRELEASED; urgency=low
       a comma.
     - cups-x2go: add correct :raw layer to binmode calls.
     - cups-x2go: fix tiny typo.
+    - cups-x2go: read data from GS and STDIN in chunks of 8 kbytes, instead of
+      everything at once. Handles large print jobs gracefully.
   * debian/control:
     - Add dependencies on perl-modules for core modules and ${perl:Depends}
       for perl itself.

--
Alioth's /srv/git/code.x2go.org/cups-x2go.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/cups-x2go.git


More information about the x2go-commits mailing list