move patient_write to share.h because it now has multiple users
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Mon, 28 Sep 2009 23:55:27 +0000 (19:55 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Mon, 28 Sep 2009 23:57:51 +0000 (19:57 -0400)
share/share.h [new file with mode: 0644]
ustd/ustd.c
ustd/ustd.h

diff --git a/share/share.h b/share/share.h
new file mode 100644 (file)
index 0000000..f674f31
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef UST_SHARE_H
+#define UST_SHARE_H
+
+#include <unistd.h>
+#include <errno.h>
+
+/* 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)
+{
+       const char *bufc = (const char *) buf;
+       int result;
+
+       for(;;) {
+               result = write(fd, bufc, count);
+               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 */
index 7d1eb49cec6de8d51157ca3c377a0d0be8d2318c..4a9a14ecdc8d29a9bd9e3b0f56b64d93ae13e5a1 100644 (file)
@@ -35,6 +35,7 @@
 #include "ustd.h"
 #include "localerr.h"
 #include "ustcomm.h"
+#include "share.h"
 
 /* return value: 0 = subbuffer is finished, it won't produce data anymore
  *               1 = got subbuffer successfully
@@ -198,30 +199,6 @@ end:
        return retval;
 }
 
-/* This write is patient because it restarts if it was incomplete.
- */
-
-ssize_t patient_write(int fd, const void *buf, size_t count)
-{
-       const char *bufc = (const char *) buf;
-       int result;
-
-       for(;;) {
-               result = write(fd, bufc, count);
-               if(result <= 0) {
-                       return result;
-               }
-               count -= result;
-               bufc += result;
-
-               if(count == 0) {
-                       break;
-               }
-       }
-
-       return bufc-(const char *)buf;
-}
-
 void decrement_active_buffers(void *arg)
 {
        pthread_mutex_lock(&active_buffers_mutex);
index 65328d61ac933312a56775fcde9599f009384309..6025213d8a9050a91d42a8ca35123f6df876e745 100644 (file)
@@ -32,8 +32,6 @@ struct buffer_info {
        s64 pidunique;
 };
 
-ssize_t patient_write(int fd, const void *buf, size_t count);
-
 void finish_consuming_dead_subbuffer(struct buffer_info *buf);
 
 #endif /* USTD_H */
This page took 0.02754 seconds and 4 git commands to generate.