Commit | Line | Data |
---|---|---|
8bf5ab2d PMF |
1 | #ifndef UST_SHARE_H |
2 | #define UST_SHARE_H | |
3 | ||
2dae156b | 4 | /* write() */ |
8bf5ab2d | 5 | #include <unistd.h> |
2dae156b PMF |
6 | |
7 | /* send() */ | |
8 | #include <sys/types.h> | |
9 | #include <sys/socket.h> | |
10 | ||
8bf5ab2d PMF |
11 | #include <errno.h> |
12 | ||
13 | /* This write is patient because it restarts if it was incomplete. | |
14 | */ | |
15 | ||
2dae156b | 16 | static __inline__ ssize_t patient_write(int fd, const void *buf, size_t count) |
8bf5ab2d PMF |
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 | ||
2dae156b PMF |
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 | ||
8bf5ab2d | 64 | #endif /* UST_SHARE_H */ |