1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "remoting/host/setup/test_util.h"
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#if defined(OS_WIN)
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <windows.h>
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#elif defined(OS_POSIX)
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <unistd.h>
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace remoting {
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
15010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)bool MakePipe(base::File* read_file,
16010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)              base::File* write_file) {
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#if defined(OS_WIN)
18010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  base::PlatformFile read_handle;
19010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  base::PlatformFile write_handle;
20010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  if (!CreatePipe(&read_handle, &write_handle, NULL, 0))
21010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    return false;
22010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  *read_file = base::File(read_handle);
23010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  *write_file = base::File(write_handle);
24010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  return true;
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#elif defined(OS_POSIX)
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  int fds[2];
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (pipe(fds) == 0) {
28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    *read_file = base::File(fds[0]);
29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    *write_file = base::File(fds[1]);
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return true;
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return false;
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#else
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#error Not implemented
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namepsace remoting
39