Show
Ignore:
Timestamp:
01/13/04 11:48:28 (20 years ago)
Author:
jalet
Message:

Small streams polling loop modification.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r1285 r1289  
    2424# 
    2525# $Log$ 
     26# Revision 1.23  2004/01/13 10:48:28  jalet 
     27# Small streams polling loop modification. 
     28# 
    2629# Revision 1.22  2004/01/12 22:43:40  jalet 
    2730# New formula to compute a job's price 
     
    251254        outdata = "" 
    252255        errdata = "" 
    253         endinput = 0 
     256        endinput = endoutput = enderr = 0 
     257        inputclosed = outclosed = errclosed = 0 
     258        self.logdebug("Entering streams polling loop...") 
    254259        status = -1 
    255         inputclosed = 0 
    256         self.logdebug("Entering streams polling loop...") 
    257260        while status == -1 : 
    258261            # First check if original backend is still alive 
     
    268271             
    269272            # In any case, deal with any remaining I/O 
    270             availablefds = pollster.poll() 
     273            availablefds = pollster.poll(5000) 
     274            if (not availablefds) and inputclosed and outputclosed and errclosed : 
     275                break 
    271276            for (fd, mask) in availablefds : 
    272277                # self.logdebug("file: %i    mask: %04x" % (fd, mask)) 
     
    277282                            os.write(fd, indata)     
    278283                            indata = "" 
     284                        if endinput :     
     285                            pollster.unregister(tocfno)         
     286                            os.close(tocfno) 
     287                            self.logdebug("Closing real backend's stdin.") 
     288                            inputclosed = 1 
    279289                    elif fd == stdoutfno : 
    280290                        if outdata : 
    281291                            os.write(fd, outdata) 
    282292                            outdata = "" 
     293                        if endoutput :     
     294                            pollster.unregister(stdoutfno)         
     295                            outputclosed = 1 
    283296                    elif fd == stderrfno : 
    284297                        if errdata : 
    285298                            os.write(fd, errdata) 
    286299                            errdata = "" 
     300                        if enderr :     
     301                            pollster.unregister(stderrfno)         
     302                            errclosed = 1 
    287303                if (mask & select.POLLIN) or (mask & select.POLLPRI) :      
    288304                    # We have something to read 
     
    291307                        indata += data 
    292308                        if not data :    # If yes, then no more input data 
     309                            pollster.unregister(infno) 
     310                            self.logdebug("Input data ends.") 
    293311                            endinput = 1 # this happens with real files. 
    294312                    elif fd == fromcfno : 
     
    302320                    #  
    303321                    # Some standard I/O stream has no more datas 
     322                    pollster.unregister(fd) 
    304323                    if fd == infno : 
    305324                        # Here we are in the case where the input file is stdin. 
    306325                        # which has no more data to be read. 
     326                        self.logdebug("Input data ends.") 
    307327                        endinput = 1 
    308328                    elif fd == fromcfno :     
    309329                        # This should never happen, since 
    310330                        # CUPS backends don't send anything on their 
    311                         # standard output 
    312                         if outdata :                 
    313                             os.write(stdoutfno, outdata) 
    314                             outdata = "" 
     331                        # standard output. 
    315332                        # We are no more interested in this file descriptor         
    316                         pollster.unregister(fromcfno)         
    317333                        os.close(fromcfno) 
    318334                        self.logdebug("Real backend's stdout ends.") 
     335                        endoutput = 1 
    319336                    elif fd == cerrfno :     
    320337                        # Original CUPS backend has finished  
    321                         # to write informations on its standard error 
    322                         if errdata :                 
    323                             # Try to write remaining info (normally "Ready to print.") 
    324                             os.write(stderrfno, errdata) 
    325                             errdata = "" 
    326                         # We are no more interested in this file descriptor         
    327                         pollster.unregister(cerrfno)         
     338                        # to write informations on its standard error. 
     339                        # We are no more interested in this file descriptor        . 
    328340                        os.close(cerrfno) 
    329341                        self.logdebug("Real backend's stderr ends.") 
    330                          
    331             if endinput and not inputclosed :             
    332                 # We deal with remaining input datas here 
    333                 # because EOF can happen in two different 
    334                 # situations and I don't want to duplicate 
    335                 # code, nor making functions. 
    336                 if indata :                 
    337                     os.write(tocfno, indata) 
    338                     indata = "" 
    339                 # Again, we're not interested in this file descriptor anymore. 
    340                 pollster.unregister(tocfno)         
    341                 os.close(tocfno) 
    342                 inputclosed = 1 
    343                 self.logdebug("Input data ends.") 
     342                        enderr = 1 
    344343                 
    345344        # Input file was a real file, we have to close it.