Index: mojo/edk/platform/platform_handle.cc |
diff --git a/mojo/edk/platform/platform_handle.cc b/mojo/edk/platform/platform_handle.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8a7c7be1b70d16eb3745e129f50932969dc49f3b |
--- /dev/null |
+++ b/mojo/edk/platform/platform_handle.cc |
@@ -0,0 +1,30 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "mojo/edk/platform/platform_handle.h" |
+ |
+#include <assert.h> |
+#include <errno.h> |
+#include <unistd.h> |
+ |
+namespace mojo { |
+namespace platform { |
+ |
+void PlatformHandle::CloseIfNecessary() { |
+ if (!is_valid()) |
+ return; |
+ |
+ if (close(fd) != 0) { |
+ // The possible errors are EBADF (which is very bad -- it indicates a bug in |
+ // our code), EINTR, or EIO. On EINTR, don't retry |close()| (this is the |
+ // correct behavior on Linux, and the only safe thing to do on Mac: see, |
+ // e.g., http://crbug.com/269623). EIO is sad (it indicates potential data |
+ // loss), but again there's nothing more to do. |
+ assert(errno == EINTR || errno == EIO); |
+ } |
+ fd = -1; |
+} |
+ |
+} // namespace embedder |
+} // namespace mojo |