Changeset 5146:716400712348 in roaraudio for libroar/proto.c


Ignore:
Timestamp:
10/15/11 12:48:07 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Moved error frame handling into proto functions (pr0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/proto.c

    r5030 r5146  
    134134 
    135135int roar_recv_message (struct roar_connection * con, struct roar_message * mes, char ** data) { 
     136 return roar_recv_message2(con, mes, data, NULL); 
     137} 
     138int roar_recv_message2 (struct roar_connection * con, struct roar_message * mes, char ** data, 
     139                        struct roar_error_frame * errorframe) { 
    136140 struct roar_vio_calls * vio; 
    137141 
     
    139143  return -1; 
    140144 
    141  return roar_vrecv_message(vio, mes, data); 
     145 return roar_vrecv_message2(vio, mes, data, errorframe); 
    142146} 
    143147 
    144148int roar_vrecv_message(struct roar_vio_calls * vio, struct roar_message * mes, char ** data) { 
     149 return roar_vrecv_message2(vio, mes, data, NULL); 
     150} 
     151 
     152int roar_vrecv_message2(struct roar_vio_calls  * vio, struct roar_message * mes, char ** data, 
     153                        struct roar_error_frame * errorframe) { 
    145154 // TODO: add CRC support. 
    146155 char buf[_ROAR_MESS_BUF_LEN_MAX]; 
     
    153162 roar_err_set(ROAR_ERROR_UNKNOWN); 
    154163 
    155  ROAR_DBG("roar_recv_message(*): try to get a response form the server..."); 
    156  
    157  if ( mes == NULL ) 
    158   return -1; 
     164 ROAR_DBG("roar_vrecv_message2(vio=%p, mes=%p, data=%p, errorframe=%p) = ?", vio, mes, data, errorframe); 
     165 
     166 ROAR_DBG("roar_vrecv_message2(*): try to get a response form the server..."); 
     167 
     168 if ( vio == NULL || mes == NULL ) { 
     169  roar_err_set(ROAR_ERROR_FAULT); 
     170  return -1; 
     171 } 
    159172 
    160173 if ( data != NULL ) 
     
    168181 } 
    169182 
    170  ROAR_DBG("roar_recv_message(*): Got a header"); 
     183 ROAR_DBG("roar_vrecv_message2(*): Got a header"); 
    171184 
    172185 mes->version = buf[0]; 
     
    224237  mes->stream = -1; 
    225238 
    226  ROAR_DBG("roar_recv_message(*): command=%i(%s)", mes->cmd, 
     239 ROAR_DBG("roar_vrecv_message2(*): command=%i(%s)", mes->cmd, 
    227240           mes->cmd == ROAR_CMD_OK ? "OK" : (mes->cmd == ROAR_CMD_ERROR ? "ERROR" : "UNKNOWN")); 
    228241 
     
    230243 
    231244 if ( mes->datalen == 0 ) { 
    232   ROAR_DBG("roar_recv_message(*): no data in this pkg"); 
    233   ROAR_DBG("roar_recv_message(*) = 0"); 
     245  ROAR_DBG("roar_vrecv_message2(*): no data in this pkg"); 
     246  if ( mes->cmd == ROAR_CMD_ERROR && errorframe != NULL ) { 
     247   roar_err_init(errorframe); 
     248  } 
    234249  roar_err_clear(); 
     250  ROAR_DBG("roar_vrecv_message2(*) = 0"); 
    235251  return 0; 
    236252 } 
     
    238254 if ( mes->datalen <= LIBROAR_BUFFER_MSGDATA ) { 
    239255  if ( roar_vio_read(vio, mes->data, mes->datalen) == mes->datalen ) { 
    240    ROAR_DBG("roar_recv_message(*): Got data!"); 
    241    ROAR_DBG("roar_recv_message(*) = 0"); 
     256   ROAR_DBG("roar_vrecv_message2(*): Got data!"); 
    242257   roar_err_clear(); 
     258   if ( mes->cmd == ROAR_CMD_ERROR && errorframe != NULL ) { 
     259    if ( roar_err_parsemsg2(mes, *data, errorframe) != 0 ) { 
     260     roar_err_init(errorframe); 
     261    } 
     262   } 
     263   ROAR_DBG("roar_vrecv_message2(*) = 0"); 
    243264   return 0; 
    244265  } 
     
    258279  if ( mes->datalen == 0 ) { 
    259280   roar_err_clear(); 
     281   if ( mes->cmd == ROAR_CMD_ERROR && errorframe != NULL ) { 
     282    roar_err_init(errorframe); 
     283   } 
    260284   return 0; 
    261285  } 
    262286 
    263287  if ( roar_vio_read(vio, *data, mes->datalen) == mes->datalen ) { 
    264    ROAR_DBG("roar_recv_message(*): Got data!"); 
    265    ROAR_DBG("roar_recv_message(*) = 0"); 
     288   ROAR_DBG("roar_vrecv_message2(*): Got data!"); 
     289 
    266290   roar_err_clear(); 
     291   if ( mes->cmd == ROAR_CMD_ERROR && errorframe != NULL ) { 
     292    if ( roar_err_parsemsg2(mes, *data, errorframe) != 0 ) { 
     293     roar_err_init(errorframe); 
     294    } 
     295   } 
     296   ROAR_DBG("roar_vrecv_message2(*) = 0"); 
    267297   return 0; 
    268298  } 
     
    277307 
    278308int roar_req (struct roar_connection * con, struct roar_message * mes, char ** data) { 
     309 return roar_req2(con, mes, data, NULL); 
     310} 
     311 
     312int roar_req2          (struct roar_connection * con, struct roar_message * mes, char ** data, 
     313                        struct roar_error_frame * errorframe) { 
    279314 struct roar_vio_calls * vio; 
    280315 
     
    282317  return -1; 
    283318 
    284  return roar_vreq(vio, mes, data); 
     319 return roar_vreq2(vio, mes, data, errorframe); 
    285320} 
    286321 
    287322int roar_vreq         (struct roar_vio_calls * vio, struct roar_message * mes, char ** data) { 
     323 return roar_vreq2(vio, mes, data, NULL); 
     324} 
     325 
     326int roar_vreq2         (struct roar_vio_calls  * vio, struct roar_message * mes, char ** data, 
     327                        struct roar_error_frame * errorframe) { 
    288328 if ( roar_vsend_message(vio, mes, data != NULL ? *data : NULL) != 0 ) 
    289329  return -1; 
     
    294334 roar_vio_sync(vio); // we need to do this becasue of ssl/compressed links 
    295335 
    296  return roar_vrecv_message(vio, mes, data); 
     336 return roar_vrecv_message2(vio, mes, data, errorframe); 
    297337} 
    298338 
Note: See TracChangeset for help on using the changeset viewer.