1f2195ee4b1311cfb6218c0331bfecf25f33d641
[ust.git] / include / share.h
1 #ifndef UST_SHARE_H
2 #define UST_SHARE_H
3
4 /* write() */
5 #include <unistd.h>
6
7 /* send() */
8 #include <sys/types.h>
9 #include <sys/socket.h>
10
11 #include <errno.h>
12
13 /* This write is patient because it restarts if it was incomplete.
14 */
15
16 static __inline__ ssize_t patient_write(int fd, const void *buf, size_t count)
17 {
18 const char *bufc = (const char *) buf;
19 int result;
20
21 for(;;) {
22 result = write(fd, bufc, count);
23 if(result == -1 && errno == EINTR) {
24 continue;
25 }
26 if(result <= 0) {
27 return result;
28 }
29 count -= result;
30 bufc += result;
31
32 if(count == 0) {
33 break;
34 }
35 }
36
37 return bufc-(const char *)buf;
38 }
39
40 static __inline__ ssize_t patient_send(int fd, const void *buf, size_t count, int flags)
41 {
42 const char *bufc = (const char *) buf;
43 int result;
44
45 for(;;) {
46 result = send(fd, bufc, count, flags);
47 if(result == -1 && errno == EINTR) {
48 continue;
49 }
50 if(result <= 0) {
51 return result;
52 }
53 count -= result;
54 bufc += result;
55
56 if(count == 0) {
57 break;
58 }
59 }
60
61 return bufc-(const char *)buf;
62 }
63
64 #endif /* UST_SHARE_H */
This page took 0.029192 seconds and 3 git commands to generate.