shithub: zuke

Download patch

ref: 91dd37b744437850197c71ca338a7ed42f3e14a2
parent: 39fa000535052d34d481f6484a5df1adcfa30948
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Feb 21 07:29:30 EST 2016

procs?threads, use ioprocs

--- a/zuke.c
+++ b/zuke.c
@@ -107,6 +107,7 @@
 	int p[2], p2[2], fd, pid, pid2;
 	char *prog;
 	Meta *m;
+	Ioproc *io;
 
 	threadsetname("cover");
 	m = m_;
@@ -122,10 +123,14 @@
 	else
 		return;
 
-	if((fd = open(m->path, OREAD)) < 0)
+	io = ioproc();
+	if((fd = ioopen(io, m->path, OREAD)) < 0){
+		closeioproc(io);
 		return;
+	}
 	if(seek(fd, m->imageoffset, 0) != m->imageoffset){
-		close(fd);
+		ioclose(io, fd);
+		closeioproc(io);
 		return;
 	}
 
@@ -137,7 +142,7 @@
 		execl(prog, prog, "-9t", nil);
 		sysfatal("execl: %r");
 	}
-	close(fd);
+	ioclose(io, fd);
 	close(p[0]);
 
 	pipe(p2);
@@ -158,6 +163,7 @@
 	postnote(PNGROUP, pid, "kill");
 	postnote(PNGROUP, pid2, "kill");
 	close(p2[1]);
+	closeioproc(io);
 }
 
 static void
@@ -165,6 +171,7 @@
 {
 	char *buf;
 	Player *player;
+	Ioproc *io;
 	ulong c;
 	int p[2], fd, pid, n, noinit;
 
@@ -203,9 +210,10 @@
 
 	pcurplaying = player->pcur;
 	redraw(screen, 0);
-	proccreate(coverload, &pl[pcurplaying], 4096);
+	threadcreate(coverload, &pl[pcurplaying], 4096);
 
-	while((n = read(p[1], buf, Relbufsz)) > 0){
+	io = ioproc();
+	while((n = ioread(io, p[1], buf, Relbufsz)) > 0){
 		c = nbrecvul(player->ctl);
 		if(c == Cstop)
 			goto stop;
@@ -214,10 +222,11 @@
 			if(c == Cstop)
 				goto stop;
 		}
-		if(write(audio, buf, n) != n)
+		if(iowrite(io, audio, buf, n) != n)
 			break;
 		byteswritten += n;
 	}
+	closeioproc(io);
 
 	if(n == 0){ /* end of the song, need to skip to the next one */
 		close(p[1]);
@@ -241,7 +250,7 @@
 	player->ctl = chancreate(sizeof(ulong), 0);
 	player->pcur = pcur;
 
-	proccreate(playerthread, player, mainstacksize);
+	threadcreate(playerthread, player, mainstacksize);
 
 	return player;
 }