Changeset 5148:73d76a74be61 in roaraudio for libroar/file.c


Ignore:
Timestamp:
10/15/11 14:29:29 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

improved error handling some more, marked some stuff as obsolete

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/file.c

    r5118 r5148  
    3636#include "libroar.h" 
    3737 
    38 #define BUFSIZE 8192 
    39 #define BUFMAX  65536 
     38#define BUFFERSIZE 8192 
     39#define BUFMAX     65536 
    4040 
    4141#ifdef ROAR_HAVE_IO_POSIX 
     
    9797#endif 
    9898 int len; 
    99  char buf[BUFSIZE]; 
     99 char buf[BUFFERSIZE]; 
    100100#if defined(__linux__) && defined(ROAR_HAVE_IPV4) 
    101101 int cork_new = 1, cork_old; 
     
    118118 // TODO: try mmap here! 
    119119 
    120  while ((len = read(in, buf, BUFSIZE)) > 0) 
     120 while ((len = read(in, buf, BUFFERSIZE)) > 0) 
    121121  r += write(out, buf, len); 
    122122 
     
    136136 int mmap_flags = 0; 
    137137 struct stat stat; 
     138 
     139 roar_debug_warn_obsolete("roar_file_map", NULL, NULL); 
    138140 
    139141 if ( mem == NULL || filename == NULL ) 
     
    183185 
    184186int     roar_file_unmap      (size_t len, void * mem) { 
     187 roar_debug_warn_obsolete("roar_file_unmap", NULL, NULL); 
     188 
    185189#ifdef ROAR_HAVE_MMAP 
    186190 return munmap(mem, len); 
     
    205209 int seek; 
    206210 int len; 
    207  char buf[BUFSIZE]; 
     211 char buf[BUFFERSIZE]; 
    208212 int rate = ROAR_RATE_DEFAULT, channels = ROAR_CHANNELS_DEFAULT, bits = ROAR_BITS_DEFAULT; 
    209213 struct roar_stream localstream[1]; 
     
    213217 ROAR_DBG("roar_file_play_full(*) = ?"); 
    214218 
    215  if ( !s ) 
     219 if ( s == NULL ) 
    216220  s = localstream; 
    217221 
    218  if ( !con ) 
    219   return -1; 
    220  
    221  if ( !file ) 
    222   return -1; 
    223  
    224  if ( exec && passfh ) 
    225   return -1; 
     222 if ( con == NULL ) { 
     223  roar_err_set(ROAR_ERROR_FAULT); 
     224  return -1; 
     225 } 
     226 
     227 if ( file == NULL ) { 
     228  roar_err_set(ROAR_ERROR_FAULT); 
     229  return -1; 
     230 } 
     231 
     232 if ( exec && passfh ) { 
     233  roar_err_set(ROAR_ERROR_INVAL); 
     234  return -1; 
     235 } 
    226236 
    227237#ifdef ROAR_TARGET_WIN32 
     
    230240 if ( (in = open(file, O_RDONLY, 0644)) == -1 ) { 
    231241#endif 
    232   return -1; 
    233  } 
    234  
    235  if ((len = read(in, buf, BUFSIZE)) < 1) { 
     242  roar_err_from_errno(); 
     243  return -1; 
     244 } 
     245 
     246 if ((len = read(in, buf, BUFFERSIZE)) < 1) { 
     247  roar_err_from_errno(); 
    236248  close(in); 
    237249  return -1; 
     
    245257 
    246258 if ( codec == -1 ) { 
    247   ROAR_ERR("roar_file_play_full(*): Unknown codec of file: %s", file); 
     259  ROAR_WARN("roar_file_play_full(*): Unknown codec of file: %s", file); 
    248260  close(in); 
     261  roar_err_set(ROAR_ERROR_BADMAGIC); 
    249262  return -1; 
    250263 } 
     
    256269 if ( exec ) { 
    257270  if ( roar_stream_new(s, rate, channels, bits, codec) == -1 ) { 
    258    ROAR_ERR("roar_file_play_full(*): Can not create new stream. This is realy BAD!"); 
     271   ROAR_DBG("roar_file_play_full(*): Can not create new stream. This is realy BAD!"); 
    259272   close(in); 
    260273   return -1; 
     
    262275 
    263276  if ( roar_stream_connect2(con, s, ROAR_DIR_PLAY, -1) == -1 ) { 
    264    ROAR_ERR("roar_file_play_full(*): Can not connect new stream to server."); 
     277   ROAR_DBG("roar_file_play_full(*): Can not connect new stream to server."); 
    265278   close(in); 
    266279   return -1; 
     
    268281 
    269282  if ( roar_stream_exec(con, s) == -1 ) { 
    270    ROAR_ERR("roar_file_play_full(*): Can not exec new stream on server."); 
     283   ROAR_DBG("roar_file_play_full(*): Can not exec new stream on server."); 
    271284   close(in); 
    272285   return -1; 
     
    275288  roar_libroar_nowarn(); 
    276289  if ( (out = roar_get_connection_fh(con)) == -1 ) { 
    277    ROAR_ERR("roar_file_play_full(*): Can not get socket of server connection for exec data transmition."); 
     290   ROAR_DBG("roar_file_play_full(*): Can not get socket of server connection for exec data transmition."); 
    278291   close(in); 
    279292   roar_libroar_warn(); 
     
    311324  close(out); 
    312325#else 
    313  while ((len = read(in, buf, BUFSIZE)) > 0) 
     326 while ((len = read(in, buf, BUFFERSIZE)) > 0) 
    314327  if ( send(out, buf, len, 0) != len ) 
    315328   break; 
     
    336349 return r; 
    337350#else 
     351 roar_err_set(ROAR_ERROR_NOSYS); 
    338352 return -1; 
    339353#endif 
     
    350364#endif 
    351365 
     366 roar_err_set(ROAR_ERROR_NODEV); 
    352367 return NULL; 
    353368} 
Note: See TracChangeset for help on using the changeset viewer.