Handle a large number of messages being published

writev has a limit for the number of iovec's that can be written at
once.  If this is exceeded, it fails to write data.  This is an
independent check from us wanting to flush if there has been too big a
quantity of data written.  A burst of small messages can trigger this.

Check for this and flush when we get to the limit.

Change-Id: Ie8096f5ae734de9f6716d2ba1846c42f6c80ff3b
diff --git a/aos/events/logging/logger.cc b/aos/events/logging/logger.cc
index e2da491..9968b80 100644
--- a/aos/events/logging/logger.cc
+++ b/aos/events/logging/logger.cc
@@ -1,6 +1,7 @@
 #include "aos/events/logging/logger.h"
 
 #include <fcntl.h>
+#include <limits.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/uio.h>
@@ -44,7 +45,10 @@
   queued_size_ += buffer.size();
   queue_.emplace_back(std::move(buffer));
 
-  if (queued_size_ > static_cast<size_t>(FLAGS_flush_size)) {
+  // Flush if we are at the max number of iovs per writev, or have written
+  // enough data.  Otherwise writev will fail with an invalid argument.
+  if (queued_size_ > static_cast<size_t>(FLAGS_flush_size) ||
+      queue_.size() == IOV_MAX) {
     Flush();
   }
 }