Changeset 5571:b46ece5b30bf in roaraudio for roard/network.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/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.