Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: metrics_library.cc

Issue 6592019: libmetrics: Support partial writes. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/metrics.git@master
Patch Set: use "" Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: metrics_library.cc
diff --git a/metrics_library.cc b/metrics_library.cc
index 3bc800716df9903034363cf678861de5d3bac8dd..8c98696c13240ce082d2c8b8af48c0a1b0e1859c 100644
--- a/metrics_library.cc
+++ b/metrics_library.cc
@@ -12,7 +12,7 @@
#include <cstdio>
#include <cstring>
-#include <base/eintr_wrapper.h>
+#include "base/eintr_wrapper.h" // HANDLE_EINTR macro, no libbase required.
#define READ_WRITE_ALL_FILE_FLAGS \
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
@@ -42,6 +42,22 @@ static void PrintError(const char* message, const char* file,
}
}
+// Copied from libbase to avoid pulling in all of libbase just for libmetrics.
+static int WriteFileDescriptor(const int fd, const char* data, int size) {
+ // Allow for partial writes.
+ ssize_t bytes_written_total = 0;
+ for (ssize_t bytes_written_partial = 0; bytes_written_total < size;
+ bytes_written_total += bytes_written_partial) {
+ bytes_written_partial =
+ HANDLE_EINTR(write(fd, data + bytes_written_total,
+ size - bytes_written_total));
+ if (bytes_written_partial < 0)
+ return -1;
+ }
+
+ return bytes_written_total;
+}
+
MetricsLibrary::MetricsLibrary()
: uma_events_file_(NULL),
consent_file_(kConsentFile) {}
@@ -155,7 +171,7 @@ bool MetricsLibrary::SendMessageToChrome(int32_t length, const char* message) {
}
bool success = true;
- if (HANDLE_EINTR(write(chrome_fd, message, length)) != length) {
+ if (WriteFileDescriptor(chrome_fd, message, length) != length) {
PrintError("write", uma_events_file_, errno);
success = false;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698