1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef IOV_H
15#define IOV_H
16
17
18
19
20
21size_t iov_size(const struct iovec *iov, const unsigned int iov_cnt);
22
23
24
25
26
27
28
29
30
31
32
33
34
35size_t iov_from_buf_full(const struct iovec *iov, unsigned int iov_cnt,
36 size_t offset, const void *buf, size_t bytes);
37size_t iov_to_buf_full(const struct iovec *iov, const unsigned int iov_cnt,
38 size_t offset, void *buf, size_t bytes);
39
40static inline size_t
41iov_from_buf(const struct iovec *iov, unsigned int iov_cnt,
42 size_t offset, const void *buf, size_t bytes)
43{
44 if (__builtin_constant_p(bytes) && iov_cnt &&
45 offset <= iov[0].iov_len && bytes <= iov[0].iov_len - offset) {
46 memcpy(iov[0].iov_base + offset, buf, bytes);
47 return bytes;
48 } else {
49 return iov_from_buf_full(iov, iov_cnt, offset, buf, bytes);
50 }
51}
52
53static inline size_t
54iov_to_buf(const struct iovec *iov, const unsigned int iov_cnt,
55 size_t offset, void *buf, size_t bytes)
56{
57 if (__builtin_constant_p(bytes) && iov_cnt &&
58 offset <= iov[0].iov_len && bytes <= iov[0].iov_len - offset) {
59 memcpy(buf, iov[0].iov_base + offset, bytes);
60 return bytes;
61 } else {
62 return iov_to_buf_full(iov, iov_cnt, offset, buf, bytes);
63 }
64}
65
66
67
68
69
70
71
72
73
74
75size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt,
76 size_t offset, int fillc, size_t bytes);
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96ssize_t iov_send_recv(int sockfd, const struct iovec *iov, unsigned iov_cnt,
97 size_t offset, size_t bytes, bool do_send);
98#define iov_recv(sockfd, iov, iov_cnt, offset, bytes) \
99 iov_send_recv(sockfd, iov, iov_cnt, offset, bytes, false)
100#define iov_send(sockfd, iov, iov_cnt, offset, bytes) \
101 iov_send_recv(sockfd, iov, iov_cnt, offset, bytes, true)
102
103
104
105
106
107
108void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt,
109 FILE *fp, const char *prefix, size_t limit);
110
111
112
113
114
115
116unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt,
117 const struct iovec *iov, unsigned int iov_cnt,
118 size_t offset, size_t bytes);
119
120
121
122
123
124
125
126
127
128size_t iov_discard_front(struct iovec **iov, unsigned int *iov_cnt,
129 size_t bytes);
130size_t iov_discard_back(struct iovec *iov, unsigned int *iov_cnt,
131 size_t bytes);
132
133typedef struct QEMUIOVector {
134 struct iovec *iov;
135 int niov;
136 int nalloc;
137 size_t size;
138} QEMUIOVector;
139
140void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
141void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov);
142void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
143void qemu_iovec_concat(QEMUIOVector *dst,
144 QEMUIOVector *src, size_t soffset, size_t sbytes);
145size_t qemu_iovec_concat_iov(QEMUIOVector *dst,
146 struct iovec *src_iov, unsigned int src_cnt,
147 size_t soffset, size_t sbytes);
148bool qemu_iovec_is_zero(QEMUIOVector *qiov);
149void qemu_iovec_destroy(QEMUIOVector *qiov);
150void qemu_iovec_reset(QEMUIOVector *qiov);
151size_t qemu_iovec_to_buf(QEMUIOVector *qiov, size_t offset,
152 void *buf, size_t bytes);
153size_t qemu_iovec_from_buf(QEMUIOVector *qiov, size_t offset,
154 const void *buf, size_t bytes);
155size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
156 int fillc, size_t bytes);
157ssize_t qemu_iovec_compare(QEMUIOVector *a, QEMUIOVector *b);
158void qemu_iovec_clone(QEMUIOVector *dest, const QEMUIOVector *src, void *buf);
159void qemu_iovec_discard_back(QEMUIOVector *qiov, size_t bytes);
160
161#endif
162