Changeset 5608:584b36c566e2 in roaraudio for libroar/proto.c


Ignore:
Timestamp:
07/31/12 15:31:35 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Handle super long client names well (Closes: #286)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/proto.c

    r5467 r5608  
    148148} 
    149149 
     150static inline int _libroar_msgresyncer(struct roar_vio_calls  * vio, size_t len) { 
     151 char buffer[2*LIBROAR_BUFFER_MSGDATA]; // this is always called with len > LIBROAR_BUFFER_MSGDATA. 
     152 ssize_t ret; 
     153 size_t errorc = 0; 
     154 
     155 while (len && errorc < 4) { 
     156  ret = roar_vio_read(vio, buffer, len > sizeof(buffer) ? sizeof(buffer) : len); 
     157  if ( ret == (size_t)-1 ) { 
     158   errorc++; 
     159  } else { 
     160   errorc = 0; 
     161   len -= ret; 
     162  } 
     163 } 
     164 
     165 if ( len ) 
     166  return -1; // last error is still set. 
     167 return 0; 
     168} 
     169 
    150170int roar_vrecv_message2(struct roar_vio_calls  * vio, struct roar_message * mes, char ** data, 
    151171                        struct roar_error_frame * errorframe) { 
     
    269289 } else { 
    270290  if ( data == NULL ) { 
    271    roar_err_set(ROAR_ERROR_MSGSIZE); 
     291   if ( _libroar_msgresyncer(vio, mes->datalen) == -1 ) { 
     292    roar_err_set(ROAR_ERROR_BADCKSUM); 
     293   } else { 
     294    roar_err_set(ROAR_ERROR_MSGSIZE); 
     295   } 
    272296   return -1; 
    273297  } 
    274298 
    275299  if ( (*data = roar_mm_malloc(mes->datalen)) == NULL ) { 
    276    roar_err_set(ROAR_ERROR_NOMEM); 
     300   if ( _libroar_msgresyncer(vio, mes->datalen) == -1 ) { 
     301    roar_err_set(ROAR_ERROR_BADCKSUM); 
     302   } else { 
     303    roar_err_set(ROAR_ERROR_NOMEM); 
     304   } 
    277305   return -1; 
    278306  } 
Note: See TracChangeset for help on using the changeset viewer.