-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.h
67 lines (67 loc) · 1.14 KB
/
block.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef _BLOCK_H_
#define _BLOCK_H_
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sendfile.h>
ssize_t Reads(int fd, void *buf, size_t count)
{
int sum = count;
while (sum)
{
int ret = read(fd, buf+count-sum, sum);
if (ret == 0)
return 0;
sum -= ret;
}
return count;
}
ssize_t Writes(int fd, void *buf, size_t count)
{
int sum = count;
while (sum)
{
int ret = write(fd, buf + count - sum, sum);
if (ret == -1)
return -1;
sum -= ret;
}
return count;
}
ssize_t Recvs(int fd, void *buf, size_t count,int flag)
{
int sum = count;
while (sum)
{
int ret = recv(fd, buf +count - sum, sum, flag);
if (ret == 0)
return 0;
sum -= ret;
}
return count;
}
ssize_t Sendfiles(int out, int in, off_t *offset, size_t count)
{
int sum = count;
while (sum)
{
int ret = sendfile(out, in, offset + count - sum, sum);
if (ret == -1)
return -1;
sum -= ret;
}
return count;
}
ssize_t Sends(int fd, void *buf, size_t count, int flag)
{
int sum = count;
while (sum)
{
int ret = send(fd, buf + count - sum, sum, flag);
if (ret == -1)
return -1;
sum -= ret;
}
return count;
}
#endif // !_BLOCK_H_