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

Side by Side Diff: mojo/common/test/test_utils_win.cc

Issue 176063002: Reland: Add some handle read/write helpers to mojo/common/test/test_utils.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
« no previous file with comments | « mojo/common/test/test_utils_posix.cc ('k') | mojo/mojo.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "mojo/common/test/test_utils.h"
6
7 #include <windows.h>
8
9 #include "mojo/system/embedder/platform_handle.h"
10
11 namespace mojo {
12 namespace test {
13
14 bool BlockingWrite(const embedder::PlatformHandle& handle,
15 const void* buffer,
16 size_t bytes_to_write,
17 size_t* bytes_written) {
18 OVERLAPPED overlapped = { 0 };
19 DWORD bytes_written_dword = 0;
20
21 if (!WriteFile(handle.handle, buffer, static_cast<DWORD>(bytes_to_write),
22 &bytes_written_dword, &overlapped)) {
23 if (GetLastError() != ERROR_IO_PENDING ||
24 !GetOverlappedResult(handle.handle, &overlapped, &bytes_written_dword,
25 TRUE)) {
26 return false;
27 }
28 }
29
30 *bytes_written = bytes_written_dword;
31 return true;
32 }
33
34 bool BlockingRead(const embedder::PlatformHandle& handle,
35 void* buffer,
36 size_t buffer_size,
37 size_t* bytes_read) {
38 OVERLAPPED overlapped = { 0 };
39 DWORD bytes_read_dword = 0;
40
41 if (!ReadFile(handle.handle, buffer, static_cast<DWORD>(buffer_size),
42 &bytes_read_dword, &overlapped)) {
43 if (GetLastError() != ERROR_IO_PENDING ||
44 !GetOverlappedResult(handle.handle, &overlapped, &bytes_read_dword,
45 TRUE)) {
46 return false;
47 }
48 }
49
50 *bytes_read = bytes_read_dword;
51 return true;
52 }
53
54 bool NonBlockingRead(const embedder::PlatformHandle& handle,
55 void* buffer,
56 size_t buffer_size,
57 size_t* bytes_read) {
58 OVERLAPPED overlapped = { 0 };
59 DWORD bytes_read_dword = 0;
60
61 if (!ReadFile(handle.handle, buffer, static_cast<DWORD>(buffer_size),
62 &bytes_read_dword, &overlapped)) {
63 if (GetLastError() != ERROR_IO_PENDING)
64 return false;
65
66 CancelIo(handle.handle);
67
68 if (!GetOverlappedResult(handle.handle, &overlapped, &bytes_read_dword,
69 TRUE)) {
70 *bytes_read = 0;
71 return true;
72 }
73 }
74
75 *bytes_read = bytes_read_dword;
76 return true;
77 }
78
79 } // namespace test
80 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/test/test_utils_posix.cc ('k') | mojo/mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698