player-mp3.c
branchtrunk
changeset 21 e47abd1f520f
parent 6 111ef8181229
child 22 93aaf15c145a
     1.1 --- a/player-mp3.c	Tue Jan 20 17:23:54 2009 +0100
     1.2 +++ b/player-mp3.c	Tue Feb 03 12:28:53 2009 +0800
     1.3 @@ -1408,14 +1408,21 @@
     1.4  
     1.5  cOutputOss::~cOutputOss()
     1.6  {
     1.7 -  close(fd);
     1.8 +  if(fd>=0) close(fd);
     1.9  }
    1.10  
    1.11  void cOutputOss::Init(void)
    1.12  {
    1.13    if(fd<0) {
    1.14      fd=open(dspdevice,O_WRONLY|O_NONBLOCK);
    1.15 -    if(fd>=0) poll.Add(fd,true);
    1.16 +    if(fd>=0) {
    1.17 +      if(fcntl(fd,F_SETFL,0)==0)
    1.18 +        poll.Add(fd,true);
    1.19 +      else {
    1.20 +        esyslog("ERROR: Cannot make dsp device '%s' blocking: %s!",dspdevice,strerror(errno));
    1.21 +        close(fd); fd=-1;
    1.22 +        }
    1.23 +      }
    1.24      else esyslog("ERROR: Cannot open dsp device '%s': %s!",dspdevice,strerror(errno));
    1.25      }
    1.26    cOutput::Init();
    1.27 @@ -1484,9 +1491,12 @@
    1.28        n=FHS;
    1.29        Data+=n; Len-=n;
    1.30        }
    1.31 -    int r=write(fd,Data,Len);
    1.32 -    if(r<0 && !FATALERRNO) r=0;
    1.33 -    if(r>=0) return n+r;
    1.34 +    if(poll.Poll(0)) {
    1.35 +      int r=write(fd,Data,Len);
    1.36 +      if(r<0 && FATALERRNO) return -1;
    1.37 +      if(r>0) n+=r;
    1.38 +      }
    1.39 +    return n;
    1.40      }
    1.41    return -1;
    1.42  }