aboutsummaryrefslogtreecommitdiff
path: root/t_write.h
diff options
context:
space:
mode:
authorKlaatu <[email protected]>2015-05-17 15:33:21 +1200
committerKlaatu <[email protected]>2015-05-17 15:33:21 +1200
commitb0de699679e8f1e39af847ed172d1ba605b4370c (patch)
tree01dac00471d61f727394e508c613b29cff0ceae5 /t_write.h
bulk upload of source
Diffstat (limited to 't_write.h')
-rw-r--r--t_write.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/t_write.h b/t_write.h
new file mode 100644
index 0000000..fde8339
--- /dev/null
+++ b/t_write.h
@@ -0,0 +1,19 @@
+/* timeout write to outfd more than 4096 bytes */
+
+static void t_write(void *buf, int len) {
+#ifndef INIT_TIMEOUT_WRITE
+ write(outfd,buf,len);
+#else
+ time_t deadline = time(0) + 1;
+ while (len > 0) {
+ int w = write(outfd,buf, (len > PIPE_BUF) ? PIPE_BUF : len);
+ if (w==-1) {
+ if (errno == EINTR) continue;
+ if (errno == EAGAIN && time(0) <= deadline) continue;
+ return;
+ }
+ len -= w;
+ buf += w;
+ }
+#endif
+}