mirror of
https://github.com/0intro/libtask
synced 2024-11-21 21:31:30 +03:00
implement fdreadn
This commit is contained in:
parent
0d454584f8
commit
02b74edba1
5
README
5
README
@ -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
16
fd.c
@ -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
1
task.h
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user