X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=include%2Fshare.h;h=1f2195ee4b1311cfb6218c0331bfecf25f33d641;hb=2dae156b134735a52d29f544e4c9e12d03baa283;hp=f674f31f590719915398d56d464e7684b7ddaf14;hpb=106e716d77762f0d27456e276be8c3df8e129eae;p=ust.git diff --git a/include/share.h b/include/share.h index f674f31..1f2195e 100644 --- a/include/share.h +++ b/include/share.h @@ -1,13 +1,19 @@ #ifndef UST_SHARE_H #define UST_SHARE_H +/* write() */ #include + +/* send() */ +#include +#include + #include /* This write is patient because it restarts if it was incomplete. */ -static inline ssize_t patient_write(int fd, const void *buf, size_t count) +static __inline__ ssize_t patient_write(int fd, const void *buf, size_t count) { const char *bufc = (const char *) buf; int result; @@ -31,4 +37,28 @@ static inline ssize_t patient_write(int fd, const void *buf, size_t count) return bufc-(const char *)buf; } +static __inline__ ssize_t patient_send(int fd, const void *buf, size_t count, int flags) +{ + const char *bufc = (const char *) buf; + int result; + + for(;;) { + result = send(fd, bufc, count, flags); + if(result == -1 && errno == EINTR) { + continue; + } + if(result <= 0) { + return result; + } + count -= result; + bufc += result; + + if(count == 0) { + break; + } + } + + return bufc-(const char *)buf; +} + #endif /* UST_SHARE_H */