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(SharedFD, cvd::Request, std::vector<SharedFD>, 36 std::optional<ucred>); 37 38 SharedFD Client() const; 39 const cvd::Request& Message() const; 40 const std::vector<SharedFD>& FileDescriptors() const; 41 SharedFD In() const; 42 SharedFD Out() const; 43 SharedFD Err() const; 44 std::optional<SharedFD> Extra() const; 45 std::optional<ucred> Credentials() const; 46 47 private: 48 SharedFD client_fd_; 49 cvd::Request message_; 50 std::vector<SharedFD> fds_; 51 std::optional<ucred> creds_; 52 }; 53 54 Result<UnixMessageSocket> GetClient(const SharedFD& client); 55 Result<std::optional<RequestWithStdio>> GetRequest(const SharedFD& client); 56 Result<void> SendResponse(const SharedFD& client, 57 const cvd::Response& response); 58 59 } // namespace cuttlefish 60