Changeset 807:9289636092cd in roaraudio


Ignore:
Timestamp:
09/17/08 17:19:00 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

set roar_errno

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/basic.c

    r701 r807  
    4343 int is_decnet = 0; 
    4444 char * obj = NULL; 
     45 
     46 roar_errno = ROAR_ERROR_UNKNOWN; 
    4547 
    4648 if ( server == NULL && (roar_server = getenv("ROAR_SERVER")) != NULL ) 
     
    114116 } 
    115117 
     118 if ( fh == -1 ) 
     119  roar_errno = ROAR_ERROR_CONNREFUSED; 
     120 
    116121 ROAR_DBG("roar_connect_raw(*) = %i", fh); 
    117122 
     
    120125 
    121126int roar_connect    (struct roar_connection * con, char * server) { 
     127 roar_errno = ROAR_ERROR_UNKNOWN; 
    122128 con->fh = roar_connect_raw(server); 
    123129 
    124130 if ( con->fh == -1 ) 
    125131  return -1; 
     132 
     133 roar_errno = ROAR_ERROR_NONE; 
    126134 
    127135 return 0; 
     
    142150 con->fh = -1; 
    143151 
     152 roar_errno = ROAR_ERROR_NONE; 
     153 
    144154 return 0; 
    145155} 
     
    150160 int max_len; 
    151161 
     162 roar_errno = ROAR_ERROR_UNKNOWN; 
     163 
    152164 ROAR_DBG("roar_identify(*): try to identify myself..."); 
    153165 
     
    184196int roar_send_message (struct roar_connection * con, struct roar_message * mes, char * data) { 
    185197 char buf[_ROAR_MESS_BUF_LEN]; 
     198 
     199 roar_errno = ROAR_ERROR_UNKNOWN; 
    186200 
    187201 ROAR_DBG("roar_send_message(*): try to send an request..."); 
     
    193207 *(uint16_t*)(buf+8) = ROAR_HOST2NET16(mes->datalen); 
    194208 
    195  if ( write(con->fh, buf, _ROAR_MESS_BUF_LEN) != _ROAR_MESS_BUF_LEN ) 
    196   return -1; 
    197  
    198  if ( mes->datalen != 0 ) 
    199   if ( write(con->fh, data == NULL ? mes->data : data, mes->datalen) != mes->datalen ) 
     209 if ( write(con->fh, buf, _ROAR_MESS_BUF_LEN) != _ROAR_MESS_BUF_LEN ) { 
     210  roar_errno = ROAR_ERROR_PIPE; 
     211  return -1; 
     212 } 
     213 
     214 if ( mes->datalen != 0 ) { 
     215  if ( write(con->fh, data == NULL ? mes->data : data, mes->datalen) != mes->datalen ) { 
     216   roar_errno = ROAR_ERROR_PIPE; 
    200217   return -1; 
     218  } 
     219 } 
     220 
     221 roar_errno = ROAR_ERROR_NONE; 
    201222 
    202223 ROAR_DBG("roar_send_message(*) = 0"); 
     
    207228 char buf[_ROAR_MESS_BUF_LEN]; 
    208229 
     230 roar_errno = ROAR_ERROR_UNKNOWN; 
     231 
    209232 ROAR_DBG("roar_recv_message(*): try to get a response form the server..."); 
    210233 
     
    212235  *data = NULL; 
    213236 
    214  if ( read(con->fh, buf, _ROAR_MESS_BUF_LEN) != _ROAR_MESS_BUF_LEN ) 
    215   return -1; 
     237 if ( read(con->fh, buf, _ROAR_MESS_BUF_LEN) != _ROAR_MESS_BUF_LEN ) { 
     238  roar_errno = ROAR_ERROR_PROTO; 
     239  return -1; 
     240 } 
    216241 
    217242 ROAR_DBG("roar_recv_message(*): Got a header"); 
    218243 
    219  if ( buf[0] != _ROAR_MESSAGE_VERSION ) 
    220   return -1; 
     244 if ( buf[0] != _ROAR_MESSAGE_VERSION ) { 
     245  roar_errno = ROAR_ERROR_PROTO; 
     246  return -1; 
     247 } 
    221248 
    222249 mes->cmd     = (unsigned char)buf[1]; 
     
    231258  ROAR_DBG("roar_recv_message(*): no data in this pkg"); 
    232259  ROAR_DBG("roar_recv_message(*) = 0"); 
     260  roar_errno = ROAR_ERROR_NONE; 
    233261  return 0; 
    234262 } 
     
    238266   ROAR_DBG("roar_recv_message(*): Got data!"); 
    239267   ROAR_DBG("roar_recv_message(*) = 0"); 
     268   roar_errno = ROAR_ERROR_NONE; 
    240269   return 0; 
    241270  } 
     271 
     272  roar_errno = ROAR_ERROR_PIPE; 
    242273  return -1; 
    243274 } else { 
    244   if ( data == NULL ) 
     275  if ( data == NULL ) { 
     276   roar_errno = ROAR_ERROR_MSGSIZE; 
    245277   return -1; 
    246  
    247   if ( (*data = malloc(mes->datalen)) == NULL ) 
     278  } 
     279 
     280  if ( (*data = malloc(mes->datalen)) == NULL ) { 
     281   roar_errno = ROAR_ERROR_NOMEM; 
    248282   return -1; 
    249  
    250   if ( mes->datalen == 0 ) 
     283  } 
     284 
     285  if ( mes->datalen == 0 ) { 
     286   roar_errno = ROAR_ERROR_NONE; 
    251287   return 0; 
     288  } 
    252289 
    253290  if ( read(con->fh, *data, mes->datalen) == mes->datalen ) { 
    254291   ROAR_DBG("roar_recv_message(*): Got data!"); 
    255292   ROAR_DBG("roar_recv_message(*) = 0"); 
     293   roar_errno = ROAR_ERROR_NONE; 
    256294   return 0; 
    257295  } 
    258   return -1; 
    259  } 
    260  
     296 
     297  roar_errno = ROAR_ERROR_PIPE; 
     298  return -1; 
     299 } 
     300 
     301 // what happened here? 
    261302 return -1; 
    262303} 
Note: See TracChangeset for help on using the changeset viewer.