ref: a7982edeb51aa586ed782996ef6aee52e6f1fba0
parent: 0c8b6da38ef0f1ac8d45d99e1b4f334091b9a252
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu Feb 25 22:48:22 EST 2016
update
--- a/zuke.c
+++ b/zuke.c
@@ -250,6 +250,7 @@
done:
if(pid < 0)
sendp(ch, nil);
+ chanclose(ch);
chanfree(ch);
if(pid >= 0)
postnote(PNGROUP, pid, "interrupt");
@@ -341,7 +342,7 @@
restart:
if((fd = open(pl[player->pcur].path, OREAD)) < 0){
fprint(2, "%r\n");
- nbsendul(player->ev, Everror);
+ sendul(player->ev, Everror);
goto freeplayer;
}
@@ -361,7 +362,7 @@
byteswritten = 0;
if(!noinit){
- nbsendul(player->ev, Evready);
+ sendul(player->ev, Evready);
buf = malloc(Relbufsz);
io = ioproc();
for(c = 0, got = 0; got < Relbufsz; got += n){
@@ -375,7 +376,7 @@
c = recvul(player->ctl);
if(c != Cstart)
goto freeplayer;
- write(audio, buf, got);
+ iowrite(io, audio, buf, got);
byteswritten = got;
bytesfrom = 0;
c = 0;
@@ -394,7 +395,8 @@
if(n < 1)
break;
- if(player->img != nil && nbrecv(player->img, &thiscover) > 0){
+ thiscover = nil;
+ if(player->img != nil && nbrecv(player->img, &thiscover) != 0){
freeimage(cover);
cover = thiscover;
redraw(screen, 0);
@@ -401,7 +403,7 @@
player->img = nil;
}
c = nbrecvul(player->ctl);
- if(c == Cstop)
+ if(c == Cstop || c == -1)
goto stop;
if(c == Ctoggle){
c = recvul(player->ctl);
@@ -417,7 +419,7 @@
c = 0;
if(bytesfrom <= byteswritten){
- if(write(audio, buf, n) != n){
+ if(iowrite(io, audio, buf, n) != n){
fprint(2, "failed to write %d bytes: %r\n", n);
break;
}
@@ -435,6 +437,7 @@
if(n == 0){ /* seeking backwards or end of the song */
close(p[1]);
if(c != Cbackward){
+ playercurr = nil;
playercurr = newplayer((player->pcur+1) % plnum, 1);
start(playercurr);
goto stop;
@@ -446,11 +449,17 @@
if(player->img != nil)
freeimage(recvp(player->img));
freeplayer:
+ if(player == playercurr)
+ playercurr = nil;
+ if(player == playernext)
+ playernext = nil;
+ chanclose(player->ctl);
+ chanclose(player->ev);
+ chanfree(player->ctl);
+ chanfree(player->ev);
close(p[1]);
closeioproc(io);
free(buf);
- chanfree(player->ctl);
- chanfree(player->ev);
free(player);
if(pid >= 0)
postnote(PNGROUP, pid, "interrupt");