X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=include%2Fshare.h;h=1f2195ee4b1311cfb6218c0331bfecf25f33d641;hb=ce45335c5700c87e9b7a6dd744a6b4b760778c4b;hp=f674f31f590719915398d56d464e7684b7ddaf14;hpb=aa08b4413291fabcbd1b1144377d37034ad361de;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 */