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/posix/eintr_wrapper.h"
11 #include "mojo/system/embedder/platform_handle.h"
16 bool BlockingWrite(const embedder::PlatformHandle
& handle
,
18 size_t bytes_to_write
,
19 size_t* bytes_written
) {
20 int original_flags
= fcntl(handle
.fd
, F_GETFL
);
21 if (original_flags
== -1 ||
22 fcntl(handle
.fd
, F_SETFL
, original_flags
& (~O_NONBLOCK
)) != 0) {
26 ssize_t result
= HANDLE_EINTR(write(handle
.fd
, buffer
, bytes_to_write
));
28 fcntl(handle
.fd
, F_SETFL
, original_flags
);
33 *bytes_written
= result
;
37 bool BlockingRead(const embedder::PlatformHandle
& handle
,
41 int original_flags
= fcntl(handle
.fd
, F_GETFL
);
42 if (original_flags
== -1 ||
43 fcntl(handle
.fd
, F_SETFL
, original_flags
& (~O_NONBLOCK
)) != 0) {
47 ssize_t result
= HANDLE_EINTR(read(handle
.fd
, buffer
, buffer_size
));
49 fcntl(handle
.fd
, F_SETFL
, original_flags
);
58 bool NonBlockingRead(const embedder::PlatformHandle
& handle
,
62 ssize_t result
= HANDLE_EINTR(read(handle
.fd
, buffer
, buffer_size
));
65 if (errno
!= EAGAIN
&& errno
!= EWOULDBLOCK
)