Changeset 4686:ebb913191f38 in roaraudio


Ignore:
Timestamp:
12/22/10 03:47:59 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added some common code for client outbuf flushing

Location:
roard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roard/clients.c

    r4684 r4686  
    2929#ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD 
    3030#ifdef ROAR_HAVE_H_ESD 
    31  {ROAR_PROTO_ESOUND, NULL, emul_esd_check_client}, 
     31 {ROAR_PROTO_ESOUND, NULL, emul_esd_check_client, NULL, NULL}, 
    3232#endif 
    3333#endif 
    3434#ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY 
    35  {ROAR_PROTO_RPLAY, NULL, emul_rplay_check_client}, 
     35 {ROAR_PROTO_RPLAY, NULL, emul_rplay_check_client, NULL, NULL}, 
    3636#endif 
    3737 {-1, NULL} 
     
    344344 struct roar_client * c; 
    345345 struct timeval tv; 
    346  fd_set r, e; 
     346 fd_set r, w, e; 
    347347 int i, j; 
    348348 int ret; 
     
    358358 
    359359 FD_ZERO(&r); 
     360 FD_ZERO(&w); 
    360361 FD_ZERO(&e); 
    361362 
     
    374375   FD_SET(fh, &r); 
    375376   FD_SET(fh, &e); 
     377 
     378   if ( g_clients[i]->outbuf != NULL ) { 
     379    FD_SET(fh, &w); 
     380   } 
    376381 
    377382   if ( fh > max_fh ) 
     
    408413  return 0; 
    409414 
    410  if ( (ret = select(max_fh + 1, &r, NULL, &e, &tv)) < 1 ) { 
     415 if ( (ret = select(max_fh + 1, &r, &w, &e, &tv)) < 1 ) { 
    411416  return ret < 0 ? ret : have; 
    412417 } 
     
    429434    } 
    430435   } 
     436   if ( FD_ISSET(fh, &w) ) { 
     437    clients_flush(i); 
     438   } 
    431439 
    432440   if ( FD_ISSET(fh, &e) ) { 
     
    458466 if ( have_streamless ) { 
    459467   FD_ZERO(&r); 
     468   FD_ZERO(&w); 
    460469 
    461470   tv.tv_sec  = 0; 
     
    476485    FD_SET(fh, &r); 
    477486 
     487    if ( g_clients[i]->outbuf != NULL ) { 
     488     FD_SET(fh, &w); 
     489    } 
     490 
    478491    if ( fh > max_fh ) 
    479492     max_fh = fh; 
    480493   } 
    481494 
    482    if ( (ret = select(max_fh + 1, &r, NULL, NULL, &tv)) < 0 ) { 
     495   if ( (ret = select(max_fh + 1, &r, &w, NULL, &tv)) < 0 ) { 
    483496    return ret; 
    484497   } 
     
    487500    if ( FD_ISSET(streamless[i].fh, &r) ) { 
    488501     clients_check(streamless[i].id); 
     502    } 
     503    if ( FD_ISSET(streamless[i].fh, &w) ) { 
     504     clients_flush(streamless[i].id); 
    489505    } 
    490506   } 
     
    602618} 
    603619 
     620int clients_flush      (int id) { 
     621 struct roar_vio_calls         vio; 
     622 struct roar_client_server   * cs; 
     623 struct roar_client          * c; 
     624 struct roard_proto          * p = NULL; 
     625 size_t i; 
     626 size_t len; 
     627 ssize_t ret; 
     628 void * buf; 
     629 
     630 _CHECK_CID(id); 
     631 
     632 c = ROAR_CLIENT(cs = g_clients[id]); 
     633 
     634 for (i = 0; g_proto[i].proto != -1; i++) { 
     635  if ( g_proto[i].proto == c->proto ) { 
     636   p = &(g_proto[i]); 
     637   break; 
     638  } 
     639 } 
     640 
     641 if ( p == NULL ) 
     642  return -1; 
     643 
     644 roar_vio_open_fh_socket(&vio, clients_get_fh(id)); 
     645 
     646 if ( p->flush_client != NULL ) { 
     647  return p->flush_client(id, &vio); 
     648 } 
     649 
     650 if ( roar_buffer_get_len(cs->outbuf, &len) == -1 ) 
     651  return -1; 
     652 
     653 if ( roar_buffer_get_data(cs->outbuf, &buf) == -1 ) 
     654  return -1; 
     655 
     656 ret = roar_vio_write(&vio, buf, len); 
     657 
     658 if ( ret < 1 ) { 
     659  clients_delete(id); 
     660  return -1; 
     661 } 
     662 
     663 if ( ret == len ) { 
     664  roar_buffer_next(&(cs->outbuf)); 
     665 } else { 
     666  if ( roar_buffer_set_offset(cs->outbuf, ret) == -1 ) { 
     667   clients_delete(id); 
     668   return -1; 
     669  } 
     670 } 
     671 
     672 if ( cs->outbuf == NULL ) { 
     673  if ( p->flushed_client != NULL ) { 
     674   return p->flushed_client(id, &vio); 
     675  } 
     676 } 
     677 
     678 return 0; 
     679} 
     680 
    604681int clients_send_mon  (struct roar_audio_info * sa, uint32_t pos) { 
    605682 int i; 
     
    674751 
    675752 return -1; 
     753} 
     754 
     755int clients_add_output (int id, struct roar_buffer * buf) { 
     756 struct roar_client_server   * cs; 
     757 
     758 _CHECK_CID(id); 
     759 cs = g_clients[id]; 
     760 
     761 if ( cs->outbuf == NULL ) { 
     762  cs->outbuf = buf; 
     763 } else { 
     764  return roar_buffer_add(cs->outbuf, buf); 
     765 } 
     766 
     767 return 0; 
    676768} 
    677769 
  • roard/include/client.h

    r4684 r4686  
    7777 int (*new_client)(int client, struct roar_vio_calls * vio, struct roard_listen * lsock); 
    7878 int (*check_client)(int client, struct roar_vio_calls * vio); 
     79 int (*flush_client)(int client, struct roar_vio_calls * vio); 
     80 int (*flushed_client)(int client, struct roar_vio_calls * vio); 
    7981}; 
    8082 
     
    104106int clients_check_all  (void); 
    105107int clients_check      (int id); 
     108int clients_flush      (int id); 
    106109int clients_send_mon   (struct roar_audio_info * sa, uint32_t pos); 
    107110int clients_send_filter(struct roar_audio_info * sa, uint32_t pos); 
     111 
     112int clients_add_output (int id, struct roar_buffer * buf); 
    108113 
    109114// proto support 
Note: See TracChangeset for help on using the changeset viewer.