Josh Gao | cbe70cb | 2016-10-18 18:17:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016, 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/cdefs.h> |
| 20 | #include <sys/types.h> |
| 21 | |
| 22 | #include <android-base/unique_fd.h> |
| 23 | |
| 24 | // *** WARNING *** |
| 25 | // tombstoned's sockets are SOCK_SEQPACKET sockets. |
| 26 | // Short reads are treated as errors and short writes are assumed to not happen. |
| 27 | |
| 28 | // Sends a packet with an attached fd. |
| 29 | ssize_t send_fd(int sockfd, const void* _Nonnull data, size_t len, android::base::unique_fd fd); |
| 30 | |
| 31 | // Receives a packet and optionally, its attached fd. |
| 32 | // If out_fd is non-null, packets can optionally have an attached fd. |
| 33 | // If out_fd is null, received packets must not have an attached fd. |
| 34 | // |
| 35 | // Errors: |
| 36 | // EOVERFLOW: sockfd is SOCK_DGRAM or SOCK_SEQPACKET and buffer is too small. |
| 37 | // The first len bytes of the packet are stored in data, but the |
| 38 | // rest of the packet is dropped. |
| 39 | // ERANGE: too many file descriptors were attached to the packet. |
| 40 | // ENOMSG: not enough file descriptors were attached to the packet. |
| 41 | // |
| 42 | // plus any errors returned by the underlying recvmsg. |
| 43 | ssize_t recv_fd(int sockfd, void* _Nonnull data, size_t len, |
| 44 | android::base::unique_fd* _Nullable out_fd); |