Changeset 5296:b7fd2c45243e in roaraudio for libroar


Ignore:
Timestamp:
11/25/11 02:27:12 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Updated connection object. (Closes: #188)

Location:
libroar
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libroar/basic.c

    r5267 r5296  
    262262int roar_connect     (struct roar_connection * con, const char * server, int flags, uint_least32_t timeout) { 
    263263 int fh; 
     264 int err; 
    264265 
    265266 if ( con == NULL ) { 
     
    274275  return -1; 
    275276 
    276  return roar_connect_fh(con, fh); 
     277 if ( roar_connect_fh(con, fh) == -1 ) { 
     278  err = roar_error; 
     279#ifdef ROAR_TARGET_WIN32 
     280  closesocket(fh); 
     281#else 
     282  close(fh); 
     283#endif 
     284  roar_error = err; 
     285  return -1; 
     286 } 
     287 
     288 if ( server != NULL ) { 
     289  con->server_name = roar_mm_strdup(server); 
     290 } 
     291 
     292 return 0; 
    277293} 
    278294 
     
    289305 
    290306 memset(con, 0, sizeof(struct roar_connection)); 
    291  con->refc        = 0; 
     307 con->refc        = 1; 
    292308 con->flags       = ROAR_CON_FLAGS_NONE; 
    293309 con->version     = 0; 
    294310 con->cb_userdata = NULL; 
    295311 con->cb          = NULL; 
     312 con->server_stds = NULL; 
     313 con->server_name = NULL; 
    296314 
    297315 roar_err_init(&(con->errorframe)); 
    298316 
    299  if ( roar_vio_open_fh_socket(&(con->viocon), fh) != -1 ) { 
     317 con->viocon = &(con->viocon_store); 
     318 
     319 if ( roar_vio_open_fh_socket(con->viocon, fh) != -1 ) { 
    300320  con->flags |= ROAR_CON_FLAGS_VIO; 
    301321 } 
     
    317337 ROAR_DBG("roar_get_connection_fh(con=%p) = ?", con); 
    318338 
    319  if ( roar_vio_ctl(&(con->viocon), ROAR_VIO_CTL_GET_FH, &fh) == -1 ) 
     339 if ( roar_vio_ctl(con->viocon, ROAR_VIO_CTL_GET_FH, &fh) == -1 ) 
    320340  return -1; 
    321341 
     
    330350 
    331351 if ( con->flags & ROAR_CON_FLAGS_VIO ) 
    332   return &(con->viocon); 
     352  return con->viocon; 
    333353 
    334354// TODO: try to open the VIO. 
     
    337357} 
    338358 
    339 int roar_disconnect (struct roar_connection * con) { 
     359const char * roar_get_connection_server(struct roar_connection * con) { 
     360 if ( con == NULL ) { 
     361  roar_err_set(ROAR_ERROR_FAULT); 
     362  return NULL; 
     363 } 
     364 
     365 return con->server_name; 
     366} 
     367 
     368int roar_connectionref(struct roar_connection * con) { 
     369 if ( con == NULL ) { 
     370  roar_err_set(ROAR_ERROR_FAULT); 
     371  return -1; 
     372 } 
     373 
     374 con->refc++; 
     375 
     376 return 0; 
     377} 
     378 
     379int roar_connectionunref(struct roar_connection * con) { 
    340380 struct roar_vio_calls * vio; 
    341381 struct roar_message m; 
     382 
     383 if ( con == NULL ) { 
     384  roar_err_set(ROAR_ERROR_FAULT); 
     385  return -1; 
     386 } 
     387 
     388 con->refc--; 
     389 
     390 if ( con->refc ) 
     391  return 0; 
    342392 
    343393 memset(&m, 0, sizeof(m)); 
     
    354404 } 
    355405 
    356  roar_connect_fh(con, -2); 
    357  
    358  roar_err_set(ROAR_ERROR_NONE); 
     406 if ( con->server_stds != NULL ) { 
     407  roar_stds_free(con->server_stds); 
     408  con->server_stds = NULL; 
     409 } 
     410 
     411 if ( con->server_name != NULL ) { 
     412  roar_mm_free(con->server_name); 
     413  con->server_name = NULL; 
     414 } 
     415 
     416 if ( con->flags & ROAR_CON_FLAGS_FREESELF ) { 
     417  roar_mm_free(con); 
     418 } else { 
     419  roar_connect_fh(con, -2); 
     420 } 
    359421 
    360422 return 0; 
  • libroar/simple.c

    r5289 r5296  
    120120 int fh; 
    121121 
    122  if ( (fh = roar_simple_stream_obj(s, rate, channels, bits, codec, NULL /* server, we hope this is ok here... */, 
     122 if ( (fh = roar_simple_stream_obj(s, rate, channels, bits, codec, roar_get_connection_server(con), 
    123123                                   dir, "libroar temp stream", mixer)) == -1 ) 
    124124  return -1; 
Note: See TracChangeset for help on using the changeset viewer.