Index: /pykota/trunk/bin/cupspykota
===================================================================
--- /pykota/trunk/bin/cupspykota (revision 1820)
+++ /pykota/trunk/bin/cupspykota (revision 1897)
@@ -24,4 +24,8 @@
 #
 # $Log$
+# Revision 1.75  2004/11/01 15:45:25  jalet
+# Added many debug messages.
+# Added some code to prevent short writes.
+#
 # Revision 1.74  2004/10/13 20:51:27  jalet
 # Made debugging levels be the same in cupspykota and lprngpykota.
@@ -531,4 +535,6 @@
         endinput = endoutput = 0
         inputclosed = outputclosed = 0
+        totaltochild = totalfromcups = 0
+        totalfromchild = totaltocups = 0
         
         if self.preserveinputfile is None :
@@ -582,9 +588,13 @@
                                 if indata :
                                     try :
-                                        os.write(fd, indata)    
+                                        nbwritten = os.write(fd, indata)    
                                     except (OSError, IOError), msg :    
                                         self.logdebug("Error while writing to real backend's stdin %s : %s" % (fd, msg))
                                     else :    
-                                        indata = ""
+                                        if len(indata) != nbwritten :
+                                            self.logdebug("Short write to real backend's input !")
+                                        totaltochild += nbwritten    
+                                        self.logdebug("%s bytes sent to real backend so far..." % totaltochild)
+                                        indata = indata[nbwritten:]
                                 else :        
                                     self.logdebug("No data to send to real backend yet, sleeping a bit...")
@@ -599,9 +609,13 @@
                                 if outdata :
                                     try :
-                                        os.write(fd, outdata)
+                                        nbwritten = os.write(fd, outdata)
                                     except (OSError, IOError), msg :    
                                         self.logdebug("Error while writing to CUPS back channel (stderr) %s : %s" % (fd, msg))
                                     else :
-                                        outdata = ""
+                                        if len(outdata) != nbwritten :
+                                            self.logdebug("Short write to stderr (CUPS) !")
+                                        totaltocups += nbwritten    
+                                        self.logdebug("%s bytes sent back to CUPS so far..." % totaltocups)
+                                        outdata = outdata[nbwritten:]
                                 else :        
                                     # self.logdebug("No data to send back to CUPS yet, sleeping a bit...") # Uncommenting this fills your logs
@@ -629,4 +643,6 @@
                                     else :    
                                         indata += data
+                                        totalfromcups += len(data)
+                                        self.logdebug("%s bytes read from CUPS so far..." % totalfromcups)
                                 elif fd == fromcfno :
                                     if not data :
@@ -635,4 +651,6 @@
                                     else :
                                         outdata += data
+                                        totalfromchild += len(data)
+                                        self.logdebug("%s bytes read from real backend so far..." % totalfromchild)
                                 else :    
                                     self.logdebug("Unexpected : %s - Sleeping a bit..." % self.formatFileEvent(fd, mask))
@@ -669,4 +687,13 @@
         
         self.logdebug("Exiting streams polling loop...")
+        
+        self.logdebug("input data's final length : %s" % len(indata))
+        self.logdebug("back-channel data's final length : %s" % len(outdata))
+        
+        self.logdebug("Total bytes read from CUPS (job's datas) : %s" % totalfromcups)
+        self.logdebug("Total bytes sent to real backend (job's datas) : %s" % totaltochild)
+        
+        self.logdebug("Total bytes read from real backend (back-channel datas) : %s" % totalfromchild)
+        self.logdebug("Total bytes sent back to CUPS (back-channel datas) : %s" % totaltocups)
         
         # Check exit code of original CUPS backend.    
