blob: 8350160419a76c51c3764e7db88adad74964cac0 [file] [log] [blame]
Andreas Huber28d35912017-03-24 13:14:11 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Steven Moreland0b8e3872019-06-25 08:54:34 -070017#pragma once
Andreas Huber28d35912017-03-24 13:14:11 -070018
19#include <android-base/macros.h>
20#include <ostream>
21#include <utils/Errors.h>
22#include <utils/RefBase.h>
23
24namespace android {
25namespace lshal {
26
27/* Creates an AF_UNIX socketpair and spawns a thread that relays any data
28 * written to the "write"-end of the pair to the specified output stream "os".
29 */
30struct PipeRelay {
31 explicit PipeRelay(std::ostream &os);
32 ~PipeRelay();
33
34 status_t initCheck() const;
35
36 // Returns the file descriptor corresponding to the "write"-end of the
37 // connection.
38 int fd() const;
39
40private:
41 struct RelayThread;
42
Andreas Huber28d35912017-03-24 13:14:11 -070043 status_t mInitCheck;
44 int mFds[2];
45 sp<RelayThread> mThread;
46
47 static void CloseFd(int *fd);
48
49 DISALLOW_COPY_AND_ASSIGN(PipeRelay);
50};
51
52} // namespace lshal
53} // namespace android