Changeset 5571:b46ece5b30bf in roaraudio for roard


Ignore:
Timestamp:
07/17/12 15:03:29 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Improved support in roard for client passing.

Location:
roard
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • roard/clients.c

    r5567 r5571  
    136136 
    137137int clients_new_from_fh(int fh, int proto, int byteorder, int update_nnode) { 
     138 return clients_new_from_fh2(fh, proto, byteorder, update_nnode, NULL, NULL, 0); 
     139} 
     140 
     141int clients_new_from_fh2(int fh, int proto, int byteorder, 
     142                         int update_nnode, 
     143                         struct roard_listen * lsock, struct sockaddr * sockaddr, socklen_t addrlen) { 
     144 const struct roard_proto_handle * protohandle; 
     145 struct roar_vio_calls    vio; 
    138146 struct roar_client * c; 
     147 int supported = 0; 
    139148 int client; 
    140149 
    141  if ( fh == -1 ) 
    142   return -1; 
    143  
    144  if ( proto != ROAR_PROTO_ROARAUDIO || byteorder != ROAR_BYTEORDER_NETWORK ) 
    145   return -1; 
    146  
    147  if ( (client = clients_new()) == -1 ) 
    148   return -1; 
    149  
    150  if ( clients_set_fh(client, fh) == -1 ) { 
    151   clients_delete(client); 
    152   return -1; 
     150 if ( fh == -1 ) { 
     151  roar_err_set(ROAR_ERROR_BADFH); 
     152  return -1; 
     153 } 
     154 
     155 if ( lsock == NULL ) { 
     156  switch (proto) { 
     157   case ROAR_PROTO_RSOUND: 
     158   case ROAR_PROTO_SIMPLE: 
     159     roar_err_set(ROAR_ERROR_FAULT); 
     160     return -1; 
     161    break; 
     162  } 
     163 } 
     164 
     165 if ( byteorder != ROAR_BYTEORDER_NETWORK ) 
     166  return -1; 
     167 
     168 
     169 if ( proto == ROAR_PROTO_RSOUND ) { 
     170#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND 
     171  client = emul_rsound_on_connect(fh, lsock); 
     172  switch (client) { 
     173   case -1: return -1; break; 
     174   case -2: return  0; break; 
     175   default: // TODO: write error handling 
     176     clients_get(client, &c); 
     177     fh = c->fh; 
     178    break; 
     179  } 
     180#else 
     181  roar_err_set(ROAR_ERROR_PROTONOSUP); 
     182  return -1; 
     183#endif 
     184 } else { 
     185  client = clients_new(); 
     186 
     187  if ( client == -1 ) { 
     188   ROAR_DBG("clients_new_from_fh2(*) = -1 // can not create new client"); 
     189   return -1; 
     190  } 
     191 
     192  if ( clients_set_fh(client, fh) == -1 ) { 
     193   ROAR_ERR("clients_new_from_fh2(*): Can not set client's fh"); 
     194 
     195   clients_delete(client); 
     196 
     197   ROAR_DBG("clients_new_from_fh2(*) = -1"); 
     198   return -1; 
     199  } 
    153200 } 
    154201 
     
    156203  if ( clients_get(client, &c) != -1 ) { 
    157204   if ( roar_nnode_free(&(c->nnode)) != -1 ) { 
    158     roar_nnode_new_from_fh(&(c->nnode), fh, 1); 
     205    if ( sockaddr != NULL && addrlen != 0 ) { 
     206     roar_nnode_new_from_sockaddr(&(c->nnode), sockaddr, addrlen); 
     207    } else { 
     208     roar_nnode_new_from_fh(&(c->nnode), fh, 1); 
     209    } 
    159210   } 
    160211  } 
    161212 } 
     213 
     214 if ( clients_set_proto(client, proto) == -1 ) { 
     215  ROAR_WARN("clients_new_from_fh2(*): Setting proto(0x%.4x) of client %i failed.", proto, client); 
     216  clients_delete(client); 
     217  return -1; 
     218 } 
     219 
     220 switch (proto) { 
     221  case ROAR_PROTO_ROARAUDIO: 
     222    // nothing needed to be done here 
     223   break; 
     224#ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD 
     225#ifdef ROAR_HAVE_H_ESD 
     226  case ROAR_PROTO_ESOUND: 
     227    ROAR_DBG("net_get_new_client(*): execing ESD CONNECT command"); 
     228 
     229    if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) 
     230     return -1; 
     231 
     232    ROAR_DBG("net_get_new_client(*): creating VIO OK"); 
     233 
     234    if ( emul_esd_exec_command(client, ESD_PROTO_CONNECT, &vio) == -1 ) 
     235     return -1; 
     236 
     237    ROAR_DBG("net_get_new_client(*): CONNECT execed sucessfully"); 
     238   break; 
     239#endif 
     240#endif 
     241#ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE 
     242  case ROAR_PROTO_SIMPLE: 
     243    if ( emul_simple_on_connect(client, lsock) == -1 ) 
     244     return -1; 
     245   break; 
     246#endif 
     247#ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND 
     248  case ROAR_PROTO_RSOUND: // nothing to do here. 
     249   break; 
     250#endif 
     251#ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY 
     252  case ROAR_PROTO_RPLAY: 
     253    if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) 
     254     return -1; 
     255 
     256    if ( emul_rplay_on_status(client, NULL, &vio, NULL, 0) == -1 ) 
     257     return -1; 
     258   break; 
     259#endif 
     260  default: 
     261    // OS independiend code to close the socket: 
     262    if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) 
     263     return -1; 
     264 
     265    protohandle = clients_get_protohandle(proto); 
     266    supported = 0; 
     267    if ( protohandle != NULL ) { 
     268     switch (protohandle->type) { 
     269      case ROARD_PROTO_TYPE_BUILDIN: 
     270        //this should not end up here. 
     271        ROAR_WARN("net_get_new_client(lsock=%p): proto(%i) marked as buildin but isn't. BAD.", lsock, proto); 
     272        supported = 0; 
     273       break; 
     274      case ROARD_PROTO_TYPE_ROARDPROTO: 
     275        supported = 1; 
     276        if ( protohandle->impl.roardproto.new_client != NULL ) { 
     277         if ( protohandle->impl.roardproto.new_client(client, &vio, lsock) == -1 ) { 
     278          supported = 0; 
     279         } 
     280        } 
     281       break; 
     282     } 
     283    } 
     284 
     285    if ( !supported ) { 
     286     clients_delete(client); 
     287     //roar_vio_close(&vio); 
     288     return -1; 
     289    } 
     290   break; 
     291 } 
     292 
    162293 
    163294 return 0; 
  • roard/include/client.h

    r5567 r5571  
    111111int clients_new        (void); 
    112112int clients_new_from_fh(int fh, int proto, int byteorder, int update_nnode); 
     113int clients_new_from_fh2(int fh, int proto, int byteorder, 
     114                         int update_nnode, 
     115                         struct roard_listen * lsock, struct sockaddr * sockaddr, socklen_t addrlen); 
    113116int clients_delete     (int id); 
    114117int clients_close      (int id, int nocheck_exec); 
  • roard/network.c

    r5567 r5571  
    7070 
    7171int net_get_new_client (struct roard_listen * lsock) { 
    72  const struct roard_proto_handle * proto; 
     72 const struct roard_proto_handle * protohandle; 
    7373 int fh; 
    7474 int client; 
     
    7979 socklen_t                addrlen = sizeof(addr); 
    8080 int supported = 0; 
     81 int proto = lsock->proto; 
    8182 
    8283 if ( roar_vio_ctl(&(lsock->sock), ROAR_VIO_CTL_GET_FH, &socket) == -1 ) { 
     
    9596  return -1; 
    9697 
    97 #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND 
    98  if ( lsock->proto == ROAR_PROTO_RSOUND ) { 
    99   client = emul_rsound_on_connect(fh, lsock); 
    100   switch (client) { 
    101    case -1: return -1; break; 
    102    case -2: return  0; break; 
    103    default: // TODO: write error handling 
    104      clients_get(client, &c); 
    105      fh = c->fh; 
    106     break; 
     98 if ( clients_new_from_fh2(fh, lsock->proto, ROAR_BYTEORDER_NETWORK, 1, lsock, (struct sockaddr*)&addr, &addrlen) == -1 ) { 
     99  if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) { 
     100   close(fh); 
     101   return -1; 
    107102  } 
    108  } else { 
    109 #endif 
    110  
    111  client = clients_new(); 
    112  
    113  if ( client == -1 ) { 
    114   ROAR_DBG("net_get_new_client(void) = -1 // can not create new client"); 
    115   close(fh); 
     103  roar_vio_close(&vio); 
    116104  return -1; 
    117105 } 
    118  
    119  if ( clients_set_fh(client, fh) == -1 ) { 
    120   ROAR_ERR("net_get_new_client(void): Can not set client's fh"); 
    121  
    122   clients_delete(client); 
    123   close(fh); 
    124  
    125   ROAR_DBG("net_get_new_client(void) = -1"); 
    126   return -1; 
    127  } 
    128 #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND 
    129  } 
    130 #endif 
    131  
    132  if ( clients_get(client, &c) != -1 ) { 
    133   if ( roar_nnode_free(&(c->nnode)) == -1 ) 
    134    return -1; 
    135  
    136   if ( roar_nnode_new_from_sockaddr(&(c->nnode), (struct sockaddr*)&addr, addrlen) == -1 ) 
    137    return -1; 
    138  } 
    139  
    140  ROAR_DBG("net_get_new_client(*): proto=0x%.4x", lsock->proto); 
    141  
    142  if ( clients_set_proto(client, lsock->proto) == -1 ) { 
    143   ROAR_WARN("net_get_new_client(*): Setting proto(0x%.4x) of client %i failed.", lsock->proto, client); 
    144   return -1; 
    145  } 
    146  
    147  switch (lsock->proto) { 
    148   case ROAR_PROTO_ROARAUDIO: 
    149     // nothing needed to be done here 
    150    break; 
    151 #ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD 
    152 #ifdef ROAR_HAVE_H_ESD 
    153   case ROAR_PROTO_ESOUND: 
    154     ROAR_DBG("net_get_new_client(*): execing ESD CONNECT command"); 
    155  
    156     if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) 
    157      return -1; 
    158  
    159     ROAR_DBG("net_get_new_client(*): creating VIO OK"); 
    160  
    161     if ( emul_esd_exec_command(client, ESD_PROTO_CONNECT, &vio) == -1 ) 
    162      return -1; 
    163  
    164     ROAR_DBG("net_get_new_client(*): CONNECT execed sucessfully"); 
    165    break; 
    166 #endif 
    167 #endif 
    168 #ifndef ROAR_WITHOUT_DCOMP_EMUL_SIMPLE 
    169   case ROAR_PROTO_SIMPLE: 
    170     if ( emul_simple_on_connect(client, lsock) == -1 ) 
    171      return -1; 
    172    break; 
    173 #endif 
    174 #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND 
    175   case ROAR_PROTO_RSOUND: // nothing to do here. 
    176    break; 
    177 #endif 
    178 #ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY 
    179   case ROAR_PROTO_RPLAY: // nothing to do here. 
    180  
    181     if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) 
    182      return -1; 
    183  
    184     if ( emul_rplay_on_status(client, NULL, &vio, NULL, 0) == -1 ) 
    185      return -1; 
    186    break; 
    187 #endif 
    188   default: 
    189     // OS independiend code to close the socket: 
    190     if ( roar_vio_open_fh_socket(&vio, fh) == -1 ) 
    191      return -1; 
    192  
    193     proto = clients_get_protohandle(lsock->proto); 
    194     supported = 0; 
    195     if ( proto != NULL ) { 
    196      switch (proto->type) { 
    197       case ROARD_PROTO_TYPE_BUILDIN: 
    198         //this should not end up here. 
    199         ROAR_WARN("net_get_new_client(lsock=%p): proto(%i) marked as buildin but isn't. BAD.", lsock, lsock->proto); 
    200         supported = 0; 
    201        break; 
    202       case ROARD_PROTO_TYPE_ROARDPROTO: 
    203         supported = 1; 
    204         if ( proto->impl.roardproto.new_client != NULL ) { 
    205          if ( proto->impl.roardproto.new_client(client, &vio, lsock) == -1 ) { 
    206           supported = 0; 
    207          } 
    208         } 
    209        break; 
    210      } 
    211     } 
    212  
    213     if ( !supported ) { 
    214      clients_delete(client); 
    215      //roar_vio_close(&vio); 
    216      return -1; 
    217     } 
    218    break; 
    219  } 
    220  
    221 // close(fh); 
    222106 
    223107 return 0; 
Note: See TracChangeset for help on using the changeset viewer.