372 | | if mask & select.POLLOUT : |
373 | | # We can write |
374 | | if fd == tocfno : |
375 | | if indata : |
376 | | os.write(fd, indata) |
377 | | try : |
378 | | os.fsync(fd) |
379 | | except OSError : |
380 | | pass |
381 | | indata = "" |
382 | | if endinput : |
383 | | self.unregisterFileNo(pollster, tocfno) |
384 | | self.logdebug("Closing real backend's stdin.") |
385 | | os.close(tocfno) |
386 | | inputclosed = 1 |
387 | | elif fd == stdoutfno : |
388 | | if outdata : |
389 | | os.write(fd, outdata) |
390 | | try : |
391 | | os.fsync(fd) |
392 | | except OSError : |
393 | | pass |
394 | | outdata = "" |
395 | | if endoutput : |
396 | | self.unregisterFileNo(pollster, stdoutfno) |
397 | | outputclosed = 1 |
398 | | elif fd == stderrfno : |
399 | | if errdata : |
400 | | os.write(fd, errdata) |
401 | | try : |
402 | | os.fsync(fd) |
403 | | except OSError : |
404 | | pass |
405 | | errdata = "" |
406 | | if enderr : |
407 | | self.unregisterFileNo(pollster, stderrfno) |
408 | | errclosed = 1 |
409 | | if (mask & select.POLLIN) or (mask & select.POLLPRI) : |
410 | | # We have something to read |
411 | | data = os.read(fd, 256 * 1024) |
412 | | if fd == infno : |
413 | | indata += data |
414 | | if not data : # If yes, then no more input data |
415 | | self.unregisterFileNo(pollster, infno) |
| 375 | try : |
| 376 | if mask & select.POLLOUT : |
| 377 | # We can write |
| 378 | if fd == tocfno : |
| 379 | if indata : |
| 380 | os.write(fd, indata) |
| 381 | try : |
| 382 | os.fsync(fd) |
| 383 | except OSError : |
| 384 | pass |
| 385 | indata = "" |
| 386 | if endinput : |
| 387 | self.unregisterFileNo(pollster, tocfno) |
| 388 | self.logdebug("Closing real backend's stdin.") |
| 389 | os.close(tocfno) |
| 390 | inputclosed = 1 |
| 391 | elif fd == stdoutfno : |
| 392 | if outdata : |
| 393 | os.write(fd, outdata) |
| 394 | try : |
| 395 | os.fsync(fd) |
| 396 | except OSError : |
| 397 | pass |
| 398 | outdata = "" |
| 399 | if endoutput : |
| 400 | self.unregisterFileNo(pollster, stdoutfno) |
| 401 | outputclosed = 1 |
| 402 | elif fd == stderrfno : |
| 403 | if errdata : |
| 404 | os.write(fd, errdata) |
| 405 | try : |
| 406 | os.fsync(fd) |
| 407 | except OSError : |
| 408 | pass |
| 409 | errdata = "" |
| 410 | if enderr : |
| 411 | self.unregisterFileNo(pollster, stderrfno) |
| 412 | errclosed = 1 |
| 413 | if (mask & select.POLLIN) or (mask & select.POLLPRI) : |
| 414 | # We have something to read |
| 415 | data = os.read(fd, 256 * 1024) |
| 416 | if fd == infno : |
| 417 | indata += data |
| 418 | if not data : # If yes, then no more input data |
| 419 | self.unregisterFileNo(pollster, infno) |
| 420 | self.logdebug("Input data ends.") |
| 421 | endinput = 1 # this happens with real files. |
| 422 | elif fd == fromcfno : |
| 423 | outdata += data |
| 424 | elif fd == cerrfno : |
| 425 | errdata += data |
| 426 | if (mask & select.POLLHUP) or (mask & select.POLLERR) : |
| 427 | # I've never seen POLLERR myself, but this probably |
| 428 | # can't hurt to treat an error condition just like |
| 429 | # an EOF. |
| 430 | # |
| 431 | # Some standard I/O stream has no more datas |
| 432 | self.unregisterFileNo(pollster, fd) |
| 433 | if fd == infno : |
| 434 | # Here we are in the case where the input file is stdin. |
| 435 | # which has no more data to be read. |
417 | | endinput = 1 # this happens with real files. |
418 | | elif fd == fromcfno : |
419 | | outdata += data |
420 | | elif fd == cerrfno : |
421 | | errdata += data |
422 | | if (mask & select.POLLHUP) or (mask & select.POLLERR) : |
423 | | # I've never seen POLLERR myself, but this probably |
424 | | # can't hurt to treat an error condition just like |
425 | | # an EOF. |
426 | | # |
427 | | # Some standard I/O stream has no more datas |
428 | | self.unregisterFileNo(pollster, fd) |
429 | | if fd == infno : |
430 | | # Here we are in the case where the input file is stdin. |
431 | | # which has no more data to be read. |
432 | | self.logdebug("Input data ends.") |
433 | | endinput = 1 |
434 | | elif fd == fromcfno : |
435 | | # This should never happen, since |
436 | | # CUPS backends don't send anything on their |
437 | | # standard output. |
438 | | # We are no more interested in this file descriptor |
439 | | self.logdebug("Closing real backend's stdout.") |
440 | | os.close(fromcfno) |
441 | | endoutput = 1 |
442 | | elif fd == cerrfno : |
443 | | # Original CUPS backend has finished |
444 | | # to write informations on its standard error. |
445 | | # We are no more interested in this file descriptor . |
446 | | self.logdebug("Closing real backend's stderr.") |
447 | | os.close(cerrfno) |
448 | | enderr = 1 |
| 437 | endinput = 1 |
| 438 | elif fd == fromcfno : |
| 439 | # This should never happen, since |
| 440 | # CUPS backends don't send anything on their |
| 441 | # standard output. |
| 442 | # We are no more interested in this file descriptor |
| 443 | self.logdebug("Closing real backend's stdout.") |
| 444 | os.close(fromcfno) |
| 445 | endoutput = 1 |
| 446 | elif fd == cerrfno : |
| 447 | # Original CUPS backend has finished |
| 448 | # to write informations on its standard error. |
| 449 | # We are no more interested in this file descriptor . |
| 450 | self.logdebug("Closing real backend's stderr.") |
| 451 | os.close(cerrfno) |
| 452 | enderr = 1 |
| 453 | except IOError : |
| 454 | pass # we got signalled during an I/O it seems |