Changeset 54:2ae42772d56f in livinglogic.python.tipimaid

Show
Ignore:
Timestamp:
12/23/08 12:17:54 (11 years ago)
Author:
Nikolas Tautenhahn <nik@…>
Branch:
default
Message:

test for each buffered line whether the server will still accept it as buffered

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • liaalh_sender.py

    r53 r54  
    104104            else: 
    105105                self.f = open(os.path.join(self.backuppath, datetime.datetime.now().strftime("%Y%m%d_recovery.log")), "a", 1) 
    106             if self.buffer: # write away all buffered entries 
     106            if self.buffer: # if we have buffered entries these must be handled before "line" 
    107107                for oldline in self.buffer: 
    108108                    self.f.write(oldline) 
     
    119119                if self.buffer: #  the good case: we have buffered entries and got our connection back before the buffertime was over 
    120120                    for (i, oldline) in enumerate(self.buffer): 
    121                         (l, t) = (len(oldline), 0) 
    122                         while t < l: # it might be that only a part of line gets transmitted 
    123                             t += self.s.send(oldline[t:]) 
    124                             try: 
    125                                 signal.alarm(2) # wait 2 seconds for server to notify us that it got the message 
    126                                 ret = self.s.recv(1024) 
    127                                 if ret == "": 
    128                                     raise socket.timeout 
    129                             except (socket.timeout, socket.error), exc: 
     121                        if datetime.datetime.now() - self.startedbuffering < self.buffertime: # make sure we are still in buffertime 
     122                            (l, t) = (len(oldline), 0) 
     123                            while t < l: # it might be that only a part of line gets transmitted 
     124                                t += self.s.send(oldline[t:]) 
     125                                try: 
     126                                    signal.alarm(2) # wait 2 seconds for server to notify us that it got the message 
     127                                    ret = self.s.recv(1024) 
     128                                    if ret == "": 
     129                                        raise socket.timeout 
     130                                except (socket.timeout, socket.error), exc: 
     131                                    signal.alarm(0) 
     132                                    self.s.close() 
     133                                    self.s = None 
     134                                    self.buffer = self.buffer[i:] # the first i items were transmitted successfully 
     135                                    return # our socket died while we were transmitting buffered items - go back to "normal" behaviour 
    130136                                signal.alarm(0) 
    131                                 self.s.close() 
    132                                 self.s = None 
    133                                 self.buffer = self.buffer[i:] # the first i items were transmitted successfully 
    134                                 return # our socket died while we were transmitting buffered items - go back to "normal" behaviour 
    135                             signal.alarm(0) 
     137                        else: # some buffered entries come to late, maybe because it took so long to wait for the server's response. 
     138                            self.s.close() # make sure that we go to this method again to write away all buffered content which is too old 
     139                            self.s = None # that's why we throw away our socket 
     140                            self.buffer = self.buffer[i:] # and the content which was transmitted to the server in time 
     141                            return 
    136142 
    137143    def send(self):