Changeset 3195 for pykota

Show
Ignore:
Timestamp:
06/27/07 18:48:21 (17 years ago)
Author:
jerome
Message:

Previous commit mistakenly included untested code.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounters/pjl.py

    r3194 r3195  
    7878        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    7979        try : 
    80             sock.settimeout(2.0) 
    8180            sock.connect((self.printerHostname, self.port)) 
    8281        except socket.error, msg : 
     
    8483            return False 
    8584        else : 
     85            sock.setblocking(False) 
    8686            self.sock = sock 
    8787            self.closed = False 
     
    9090            self.readthread = threading.Thread(target=self.readloop) 
    9191            self.readthread.start() 
    92             time.sleep(1) 
    9392            self.parent.filter.logdebug("Connected to printer %s:%s" % (self.printerHostname, self.port)) 
    9493            return True 
     
    114113        while not self.quitEvent.isSet() : 
    115114            try : 
    116                 answer = self.sock.recv(1) 
    117             except socket.timeout :     
    118                 self.parent.filter.logdebug("Timed out when reading answer from %s:%s" \ 
    119                                                 % (self.printerHostname, self.port)) 
     115                answer = self.sock.recv(4096) 
    120116            except socket.error, (err, msg) : 
    121                 self.parent.filter.printInfo(_("Problem while receiving PJL answer from %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn") 
     117                time.sleep(0.1) # We will try again later in all cases 
     118                if err != errno.EAGAIN : 
     119                    self.parent.filter.printInfo(_("Problem while receiving PJL answer from %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn") 
    122120            else :     
    123121                if answer : 
     
    133131        """Retrieves a printer's internal page counter and status via PJL.""" 
    134132        try : 
    135             nbsent = self.sock.send(pjlMessage) 
    136             if nbsent != len(pjlMessage) : 
    137                 raise socket.error, "Short write" 
     133            self.sock.sendall(pjlMessage) 
    138134        except socket.error, msg : 
    139135            self.parent.filter.printInfo(_("Problem while sending PJL query to %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn")