1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/common/test/test_utils.h"
10 #include "base/base_paths.h"
11 #include "base/path_service.h"
12 #include "base/posix/eintr_wrapper.h"
13 #include "mojo/embedder/platform_handle.h"
18 bool BlockingWrite(const embedder::PlatformHandle& handle,
20 size_t bytes_to_write,
21 size_t* bytes_written) {
22 int original_flags = fcntl(handle.fd, F_GETFL);
23 if (original_flags == -1 ||
24 fcntl(handle.fd, F_SETFL, original_flags & (~O_NONBLOCK)) != 0) {
28 ssize_t result = HANDLE_EINTR(write(handle.fd, buffer, bytes_to_write));
30 fcntl(handle.fd, F_SETFL, original_flags);
35 *bytes_written = result;
39 bool BlockingRead(const embedder::PlatformHandle& handle,
43 int original_flags = fcntl(handle.fd, F_GETFL);
44 if (original_flags == -1 ||
45 fcntl(handle.fd, F_SETFL, original_flags & (~O_NONBLOCK)) != 0) {
49 ssize_t result = HANDLE_EINTR(read(handle.fd, buffer, buffer_size));
51 fcntl(handle.fd, F_SETFL, original_flags);
60 bool NonBlockingRead(const embedder::PlatformHandle& handle,
64 ssize_t result = HANDLE_EINTR(read(handle.fd, buffer, buffer_size));
67 if (errno != EAGAIN && errno != EWOULDBLOCK)
78 base::FilePath GetFilePathForJSResource(const std::string& path) {
79 std::string binding_path = "gen/" + path + ".js";
80 base::FilePath exe_dir;
81 PathService::Get(base::DIR_EXE, &exe_dir);
82 return exe_dir.AppendASCII(binding_path);