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

Unified Diff: net/base/file_stream_posix.cc

Issue 100225: POSIX: Add a macro for handling EINTR. (Closed)
Patch Set: ... Created 11 years, 8 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 | « chrome/common/transport_dib_mac.cc ('k') | net/base/listen_socket.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/file_stream_posix.cc
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc
index d1b70eba465c2a019a8d53dfcef558a252d04b74..7f3c9fbc58eb07e1b48220630dcc0e6368fb5f54 100644
--- a/net/base/file_stream_posix.cc
+++ b/net/base/file_stream_posix.cc
@@ -14,6 +14,7 @@
#include <errno.h>
#include "base/basictypes.h"
+#include "base/eintr_wrappers.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/string_util.h"
@@ -51,30 +52,20 @@ int ReadFile(base::PlatformFile file, char* buf, int buf_len) {
// read(..., 0) returns 0 to indicate end-of-file.
// Loop in the case of getting interrupted by a signal.
- for (;;) {
- ssize_t res = read(file, buf, static_cast<size_t>(buf_len));
- if (res == static_cast<ssize_t>(-1)) {
- if (errno == EINTR)
- continue;
- return MapErrorCode(errno);
- }
- return static_cast<int>(res);
- }
+ ssize_t res = HANDLE_EINTR(read(file, buf, static_cast<size_t>(buf_len)));
+ if (res == static_cast<ssize_t>(-1))
+ return MapErrorCode(errno);
+ return static_cast<int>(res);
}
// WriteFile() is a simple wrapper around write() that handles EINTR signals and
// calls MapErrorCode() to map errno to net error codes. It tries to write to
// completion.
int WriteFile(base::PlatformFile file, const char* buf, int buf_len) {
- while (true) {
- ssize_t res = write(file, buf, buf_len);
- if (res == -1) {
- if (errno == EINTR)
- continue;
- return MapErrorCode(errno);
- }
- return res;
- }
+ ssize_t res = HANDLE_EINTR(write(file, buf, buf_len));
+ if (res == -1)
+ return MapErrorCode(errno);
+ return res;
}
// BackgroundReadTask is a simple task that reads a file and then runs
« no previous file with comments | « chrome/common/transport_dib_mac.cc ('k') | net/base/listen_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698