Changeset 807:9289636092cd in roaraudio
- Timestamp:
- 09/17/08 17:19:00 (16 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/basic.c
r701 r807 43 43 int is_decnet = 0; 44 44 char * obj = NULL; 45 46 roar_errno = ROAR_ERROR_UNKNOWN; 45 47 46 48 if ( server == NULL && (roar_server = getenv("ROAR_SERVER")) != NULL ) … … 114 116 } 115 117 118 if ( fh == -1 ) 119 roar_errno = ROAR_ERROR_CONNREFUSED; 120 116 121 ROAR_DBG("roar_connect_raw(*) = %i", fh); 117 122 … … 120 125 121 126 int roar_connect (struct roar_connection * con, char * server) { 127 roar_errno = ROAR_ERROR_UNKNOWN; 122 128 con->fh = roar_connect_raw(server); 123 129 124 130 if ( con->fh == -1 ) 125 131 return -1; 132 133 roar_errno = ROAR_ERROR_NONE; 126 134 127 135 return 0; … … 142 150 con->fh = -1; 143 151 152 roar_errno = ROAR_ERROR_NONE; 153 144 154 return 0; 145 155 } … … 150 160 int max_len; 151 161 162 roar_errno = ROAR_ERROR_UNKNOWN; 163 152 164 ROAR_DBG("roar_identify(*): try to identify myself..."); 153 165 … … 184 196 int roar_send_message (struct roar_connection * con, struct roar_message * mes, char * data) { 185 197 char buf[_ROAR_MESS_BUF_LEN]; 198 199 roar_errno = ROAR_ERROR_UNKNOWN; 186 200 187 201 ROAR_DBG("roar_send_message(*): try to send an request..."); … … 193 207 *(uint16_t*)(buf+8) = ROAR_HOST2NET16(mes->datalen); 194 208 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; 200 217 return -1; 218 } 219 } 220 221 roar_errno = ROAR_ERROR_NONE; 201 222 202 223 ROAR_DBG("roar_send_message(*) = 0"); … … 207 228 char buf[_ROAR_MESS_BUF_LEN]; 208 229 230 roar_errno = ROAR_ERROR_UNKNOWN; 231 209 232 ROAR_DBG("roar_recv_message(*): try to get a response form the server..."); 210 233 … … 212 235 *data = NULL; 213 236 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 } 216 241 217 242 ROAR_DBG("roar_recv_message(*): Got a header"); 218 243 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 } 221 248 222 249 mes->cmd = (unsigned char)buf[1]; … … 231 258 ROAR_DBG("roar_recv_message(*): no data in this pkg"); 232 259 ROAR_DBG("roar_recv_message(*) = 0"); 260 roar_errno = ROAR_ERROR_NONE; 233 261 return 0; 234 262 } … … 238 266 ROAR_DBG("roar_recv_message(*): Got data!"); 239 267 ROAR_DBG("roar_recv_message(*) = 0"); 268 roar_errno = ROAR_ERROR_NONE; 240 269 return 0; 241 270 } 271 272 roar_errno = ROAR_ERROR_PIPE; 242 273 return -1; 243 274 } else { 244 if ( data == NULL ) 275 if ( data == NULL ) { 276 roar_errno = ROAR_ERROR_MSGSIZE; 245 277 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; 248 282 return -1; 249 250 if ( mes->datalen == 0 ) 283 } 284 285 if ( mes->datalen == 0 ) { 286 roar_errno = ROAR_ERROR_NONE; 251 287 return 0; 288 } 252 289 253 290 if ( read(con->fh, *data, mes->datalen) == mes->datalen ) { 254 291 ROAR_DBG("roar_recv_message(*): Got data!"); 255 292 ROAR_DBG("roar_recv_message(*) = 0"); 293 roar_errno = ROAR_ERROR_NONE; 256 294 return 0; 257 295 } 258 return -1; 259 } 260 296 297 roar_errno = ROAR_ERROR_PIPE; 298 return -1; 299 } 300 301 // what happened here? 261 302 return -1; 262 303 }
Note: See TracChangeset
for help on using the changeset viewer.