Changeset 6186

Show
Ignore:
Timestamp:
01/31/13 09:30:53 (6 years ago)
Author:
sportzer
Message:

More shim fixes.

Location:
seattle/branches/repy_v2/shims
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • seattle/branches/repy_v2/shims/compressionshim.repy

    r6156 r6186  
    7676    self.close_lock.release() 
    7777 
    78     try: 
     78    empty = self._empty_lock.acquire(False) 
     79    mutex = self._mutex_lock.acquire(False) 
     80    if mutex and empty: 
     81      self._send_buf = '' 
     82      self._mutex_lock.release() 
    7983      self._full_lock.release() 
    80     except Exception: 
    81       pass 
     84    else: 
     85      # Release any lock we may have successfully acquired: 
     86      if empty: 
     87        self._empty_lock.release() 
     88      if mutex: 
     89        self._mutex_lock.release() 
    8290 
    8391    return result 
     
    185193    """ 
    186194 
     195    if self.closed_local: 
     196      raise SocketClosedLocal("Socket closed locally!") 
     197 
     198    if self.closed_remote: 
     199      raise SocketClosedRemote("Socket closed remotely!") 
     200 
    187201    # Get the result buffer out of the dictionary. 
    188202    result_buf = self._result_buf 
     
    289303        # is more data to send 
    290304        self._mutex_lock.release() 
    291         try: 
    292           self._empty_lock.release() 
    293         except Exception: 
    294           pass 
     305        self._empty_lock.release() 
    295306 
    296307 
  • seattle/branches/repy_v2/shims/hidesizeshim.repy

    r6156 r6186  
    7777 
    7878    """ 
     79 
     80    if self.closed_local: 
     81      raise SocketClosedLocal("Socket closed locally!") 
     82 
     83    if self.closed_remote: 
     84      raise SocketClosedRemote("Socket closed remotely!") 
     85 
    7986    # How much of the original data has been sent successfully. 
    8087    total_original_bytes_sent = 0 
    8188 
    82     # Keep sending the supplied message until no more data to send. 
    83     while msg: 
    84  
    85       # Create a bloated chunk of data out of the original message. 
    86       header = "" 
    87  
    88      
    89       msg_length = len(msg) 
    90       # Don't send more "junk" data than the original message data 
    91       extradata_length = min(random_int_below(self.shim._MAX_BYTES),random_int_below(len(msg))) 
    92       extradata = ''.join(random_sample(list(msg),extradata_length)) 
    93  
    94       # Append header information to indicate the length of the block 
    95       header += str(msg_length) + ',' + str(extradata_length) + ',' 
    96       body = msg + extradata 
    97  
    98       # Block is comprised of header and data + extra data 
    99       block_data = header + body 
    100  
    101  
    102       # If the send buffer is empty, place this block in the send buffer 
    103       empty = self._empty_lock.acquire(False) 
    104       mutex = self._mutex_lock.acquire(False) 
    105       if mutex and empty: 
    106         self._send_buf = block_data 
     89    # Create a bloated chunk of data out of the original message. 
     90    header = "" 
     91 
     92   
     93    msg_length = len(msg) 
     94    # Don't send more "junk" data than the original message data 
     95    extradata_length = min(random_int_below(self.shim._MAX_BYTES),random_int_below(len(msg))) 
     96    extradata = ''.join(random_sample(list(msg),extradata_length)) 
     97 
     98    # Append header information to indicate the length of the block 
     99    header += str(msg_length) + ',' + str(extradata_length) + ',' 
     100    body = msg + extradata 
     101 
     102    # Block is comprised of header and data + extra data 
     103    block_data = header + body 
     104 
     105 
     106    # If the send buffer is empty, place this block in the send buffer 
     107    empty = self._empty_lock.acquire(False) 
     108    mutex = self._mutex_lock.acquire(False) 
     109    if mutex and empty: 
     110      self._send_buf = block_data 
     111      self._mutex_lock.release() 
     112      self._full_lock.release() 
     113      total_original_bytes_sent += len(msg) 
     114    else: 
     115      # Release any lock we may have successfully acquired: 
     116      if empty: 
     117        self._empty_lock.release() 
     118      if mutex: 
    107119        self._mutex_lock.release() 
    108         self._full_lock.release() 
    109         total_original_bytes_sent += len(msg) 
    110       else: 
    111         # Release any lock we may have successfully acquired: 
    112         if empty: 
    113           self._empty_lock.release() 
    114         if mutex: 
    115           self._mutex_lock.release() 
    116         break 
    117120 
    118121    # If we have not sent any data, then the send buffer the system's send buffer must be full  
     
    136139 
    137140    """ 
     141 
     142    if self.closed_local: 
     143      raise SocketClosedLocal("Socket closed locally!") 
     144 
     145    if self.closed_remote: 
     146      raise SocketClosedRemote("Socket closed remotely!") 
    138147 
    139148    # Get the result buffer out of the dictionary. 
     
    203212    self.close_lock.release() 
    204213 
    205     try: 
     214    empty = self._empty_lock.acquire(False) 
     215    mutex = self._mutex_lock.acquire(False) 
     216    if mutex and empty: 
     217      self._send_buf = '' 
     218      self._mutex_lock.release() 
    206219      self._full_lock.release() 
    207     except Exception: 
    208       pass 
     220    else: 
     221      # Release any lock we may have successfully acquired: 
     222      if empty: 
     223        self._empty_lock.release() 
     224      if mutex: 
     225        self._mutex_lock.release() 
    209226 
    210227    return result 
     
    317334        # is more data to send 
    318335        self._mutex_lock.release() 
    319         try: 
    320           self._empty_lock.release() 
    321         except Exception: 
    322           pass 
     336        self._empty_lock.release() 
    323337 
    324338