Changeset 5571:b46ece5b30bf in roaraudio for roard/clients.c


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.

File:
1 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; 
Note: See TracChangeset for help on using the changeset viewer.