Changeset 5396:e2e5f307ef8b in roaraudio for libroar


Ignore:
Timestamp:
01/24/12 01:22:31 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

better support for ROAR_VIOF_NONBLOCK

Location:
libroar
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libroar/vio_proto.c

    r5381 r5396  
    4646 char                     * ed; 
    4747 char                     * tmp; 
     48 int                        flags = ROAR_VIOF_READWRITE; 
    4849 
    4950 if ( def == NULL ) 
     
    6162  dstr = "//"; 
    6263 
    63  if ( roar_vio_dstr_init_defaults(def, ROAR_VIO_DEF_TYPE_SOCKET, O_RDWR, 0644) == -1 ) 
     64 if ( odef->o_flags & ROAR_VIOF_NONBLOCK ) 
     65  flags |= ROAR_VIOF_NONBLOCK; 
     66 
     67 if ( roar_vio_dstr_init_defaults(def, ROAR_VIO_DEF_TYPE_SOCKET, flags, 0644) == -1 ) 
    6468  return -1; 
    6569 
     
    100104 const char * host; 
    101105 char * tmp; 
     106 int    ret; 
    102107 
    103108 ROAR_DBG("roar_vio_open_proto(calls=%p, dst=%p, dstr='%s', proto=%i, odef=%p) = ?", calls, dst, dstr, proto, odef); 
     
    169174 self->proto = proto; 
    170175 
     176 if ( odef->o_flags & ROAR_VIOF_NONBLOCK ) { 
     177  if ( roar_vio_nonblock(calls, ROAR_SOCKET_BLOCK) == -1 ) { 
     178   return -1; 
     179  } 
     180 } 
    171181 switch (proto) { 
    172182  case ROAR_VIO_PROTO_P_HTTP: 
    173183  case ROAR_VIO_PROTO_P_ICY: 
    174     return roar_vio_open_proto_http(calls, dst, host, dstr, userpass.user != NULL ? &userpass : NULL); 
     184    ret = roar_vio_open_proto_http(calls, dst, host, dstr, userpass.user != NULL ? &userpass : NULL); 
    175185   break; 
    176186  case ROAR_VIO_PROTO_P_GOPHER: 
    177     return roar_vio_open_proto_gopher(calls, dst, host, dstr); 
    178    break; 
    179  } 
    180  
    181  ROAR_DBG("roar_vio_open_proto(*) = -1 // no matching protocol"); 
    182  return -1; 
     187    ret = roar_vio_open_proto_gopher(calls, dst, host, dstr); 
     188   break; 
     189  default: 
     190    ROAR_DBG("roar_vio_open_proto(*) = -1 // no matching protocol"); 
     191    roar_err_set(ROAR_ERROR_NOTSUP); 
     192    ret = -1; 
     193   break; 
     194 } 
     195 if ( odef->o_flags & ROAR_VIOF_NONBLOCK ) { 
     196  if ( roar_vio_nonblock(calls, ROAR_SOCKET_NONBLOCK) == -1 ) { 
     197   return -1; 
     198  } 
     199 } 
     200 
     201 return ret; 
    183202#else 
    184203 return -1; 
     
    497516 ROAR_DBG("roar_vio_open_proto_http(calls=%p, dst=%p, host='%s', file='%s') = ?", calls, dst, host, file); 
    498517 
    499  roar_vio_printf(dst, "GET /%s HTTP/1.1\r\n", file); 
     518 if ( roar_vio_printf(dst, "GET /%s HTTP/1.1\r\n", file) == -1 ) 
     519  return -1; 
     520 
    500521 roar_vio_printf(dst, "Host: %s\r\n", host); 
    501522 roar_vio_printf(dst, "User-Agent: roar_vio_open_proto_http() $Revision$\r\n"); 
  • libroar/vio_socket.c

    r5381 r5396  
    171171  } 
    172172 } else { 
     173  if ( def->o_flags & ROAR_VIOF_NONBLOCK ) { 
     174   if ( roar_socket_nonblock(fh, ROAR_SOCKET_NONBLOCK) == -1 ) { 
     175    close(fh); 
     176    return -1; 
     177   } 
     178  } 
     179 
    173180  if ( connect(fh, &(def->d.socket.sa.sa), len) == -1 ) { 
    174    close(fh); 
    175    return -1; 
     181   if ( errno != EINPROGRESS ) { 
     182    roar_err_from_errno(); 
     183    close(fh); 
     184    return -1; 
     185   } 
    176186  } 
    177187 } 
Note: See TracChangeset for help on using the changeset viewer.