1 /* 2 * Copyright (C) 2022 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 17 #pragma once 18 19 #include <sys/socket.h> 20 21 #include <memory> 22 #include <optional> 23 #include <vector> 24 25 #include "cvd_server.pb.h" 26 27 #include "common/libs/fs/shared_fd.h" 28 #include "common/libs/utils/result.h" 29 #include "common/libs/utils/unix_sockets.h" 30 31 namespace cuttlefish { 32 33 class RequestWithStdio { 34 public: 35 RequestWithStdio(cvd::Request, std::vector<SharedFD>, std::optional<ucred>); 36 37 const cvd::Request& Message() const; 38 const std::vector<SharedFD>& FileDescriptors() const; 39 SharedFD In() const; 40 SharedFD Out() const; 41 SharedFD Err() const; 42 std::optional<SharedFD> Extra() const; 43 std::optional<ucred> Credentials() const; 44 45 private: 46 cvd::Request message_; 47 std::vector<SharedFD> fds_; 48 std::optional<ucred> creds_; 49 }; 50 51 Result<UnixMessageSocket> GetClient(const SharedFD& client); 52 Result<std::optional<RequestWithStdio>> GetRequest(const SharedFD& client); 53 Result<void> SendResponse(const SharedFD& client, 54 const cvd::Response& response); 55 56 } // namespace cuttlefish 57