This allows for future unit testing of the log infrastructure.
const char * start = special_buf + msg_index;
const char * end = start;
while (*end != '\n') end++;
- int r = write(fd, start, end - start + 1);
+ int r = bp_sys::write(fd, start, end - start + 1);
if (r >= 0) {
if (start + r > end) {
// All written: go on to next message in queue
iovs_to_write = 2;
}
- ssize_t r = writev(fd, logiov, iovs_to_write);
+ ssize_t r = bp_sys::writev(fd, logiov, iovs_to_write);
if (r >= 0) {
bool complete = (r == len) && will_complete;
#ifndef BPSYS_INCLUDED
#define BPSYS_INCLUDED
-#include "dasynq.h"
+#include "dasynq.h" // for pipe2
+
+#include <sys/uio.h> // writev
+#include <unistd.h>
+#include <fcntl.h>
namespace bp_sys {
using ::getpgrp;
using ::read;
using ::write;
+using ::writev;
// Wrapper around a POSIX exit status
class exit_status
return count;
}
+ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
+{
+ ssize_t r = 0;
+ for (int i = 0; i < iovcnt; i++) {
+ ssize_t wr = write(fd, iov[i].iov_base, iov[i].iov_len);
+ if (wr < 0) {
+ if (r > 0) {
+ return r;
+ }
+ return wr;
+ }
+ r += wr;
+ if (size_t(wr) < iov[i].iov_len) {
+ return r;
+ }
+ }
+ return r;
+}
+
}
#include <sys/types.h>
#include <unistd.h>
+#include <sys/uio.h>
// Mock system functions for testing.
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
+ssize_t writev (int fd, const struct iovec *iovec, int count);
}