2 * SPDX-License-Identifier: LGPL-2.1-or-later
4 * Copyright (C) 2009 Pierre-Marc Fournier
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
17 #include <sys/types.h>
18 #include <sys/socket.h>
22 #include <ust-share.h>
25 * This write is patient because it restarts if it was incomplete.
28 ssize_t
ust_patient_write(int fd
, const void *buf
, size_t count
)
30 const char *bufc
= (const char *) buf
;
34 result
= write(fd
, bufc
, count
);
35 if (result
== -1 && errno
== EINTR
) {
49 return bufc
-(const char *)buf
;
53 * The `struct iovec *iov` is not `const` because we modify it to support
56 ssize_t
ust_patient_writev(int fd
, struct iovec
*iov
, int iovcnt
)
58 ssize_t written
, total_written
= 0;
59 int curr_element_idx
= 0;
62 written
= writev(fd
, iov
+ curr_element_idx
,
63 iovcnt
- curr_element_idx
);
64 if (written
== -1 && errno
== EINTR
) {
71 total_written
+= written
;
74 * If it's not the last element in the vector and we have
75 * written more than the current element size, then increment
76 * the current element index until we reach the element that
77 * was partially written.
79 while (curr_element_idx
< iovcnt
&&
80 written
>= iov
[curr_element_idx
].iov_len
) {
81 written
-= iov
[curr_element_idx
].iov_len
;
85 /* Maybe we are done. */
86 if (curr_element_idx
>= iovcnt
) {
90 /* Update the current element base and size. */
91 iov
[curr_element_idx
].iov_base
+= written
;
92 iov
[curr_element_idx
].iov_len
-= written
;
98 ssize_t
ust_patient_send(int fd
, const void *buf
, size_t count
, int flags
)
100 const char *bufc
= (const char *) buf
;
104 result
= send(fd
, bufc
, count
, flags
);
105 if (result
== -1 && errno
== EINTR
) {
119 return bufc
- (const char *) buf
;
This page took 0.035266 seconds and 4 git commands to generate.