implement fdreadn

This commit is contained in:
David du Colombier 2014-08-03 18:51:25 +02:00
parent 0d454584f8
commit 02b74edba1
3 changed files with 22 additions and 0 deletions

5
README
View File

@ -98,6 +98,11 @@ int fdread(int, void*, int);
Like regular read(), but puts task to sleep while waiting for Like regular read(), but puts task to sleep while waiting for
data instead of blocking the whole program. data instead of blocking the whole program.
int fdreadn(int, void*, int);
Like fdread(), but does successive read calls until n bytes have
been read, or a read system call returns a non-positive count.
int fdwrite(int, void*, int); int fdwrite(int, void*, int);
Like regular write(), but puts task to sleep while waiting to Like regular write(), but puts task to sleep while waiting to

16
fd.c
View File

@ -290,6 +290,22 @@ fdread(int fd, void *buf, int n)
return m; return m;
} }
int
fdreadn(int fd, void *buf, int n)
{
int m, tot;
for(tot=0; tot<n; tot+=m){
m = fdread(fd, (char*)buf+tot, n-tot);
if(m < 0)
return m;
if(m == 0)
break;
}
return tot;
}
int int
fdwrite(int fd, void *buf, int n) fdwrite(int fd, void *buf, int n)
{ {

1
task.h
View File

@ -154,6 +154,7 @@ int chansendul(Channel *c, unsigned long v);
*/ */
int fdread(int, void*, int); int fdread(int, void*, int);
int fdread1(int, void*, int); /* always uses fdwait */ int fdread1(int, void*, int); /* always uses fdwait */
int fdreadn(int, void*, int);
int fdwrite(int, void*, int); int fdwrite(int, void*, int);
void fdwait(int, int); void fdwait(int, int);
int fdnoblock(int); int fdnoblock(int);