Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:47:27

0001 /*
0002  * Copyright (c) 2008-2014 Cisco Systems, Inc.  All rights reserved.
0003  * Copyright (c) 2009      Sandia National Laboratories. All rights reserved.
0004  * Copyright (c) 2014-2020 Intel, Inc.  All rights reserved.
0005  *
0006  * Copyright (c) 2015      Research Organization for Information Science
0007  *                         and Technology (RIST). All rights reserved.
0008  * Copyright (c) 2021-2022 Nanook Consulting.  All rights reserved.
0009  * $COPYRIGHT$
0010  *
0011  * Additional copyrights may follow
0012  *
0013  * $HEADER$
0014  */
0015 
0016 /* @file */
0017 
0018 #ifndef PMIX_UTIL_FD_H_
0019 #define PMIX_UTIL_FD_H_
0020 
0021 #include "src/include/pmix_config.h"
0022 #include "pmix_common.h"
0023 
0024 BEGIN_C_DECLS
0025 
0026 /**
0027  * Read a complete buffer from a file descriptor.
0028  *
0029  * @param fd File descriptor
0030  * @param len Number of bytes to read
0031  * @param buffer Pre-allocated buffer (large enough to hold len bytes)
0032  *
0033  * @returns PMIX_SUCCESS upon success.
0034  * @returns PMIX_ERR_TIMEOUT if the fd closes before reading the full amount.
0035  * @returns PMIX_ERR_IN_ERRNO otherwise.
0036  *
0037  * Loop over reading from the fd until len bytes are read or an error
0038  * occurs.  EAGAIN and EINTR are transparently handled.
0039  */
0040 PMIX_EXPORT pmix_status_t pmix_fd_read(int fd, int len, void *buffer);
0041 
0042 /**
0043  * Write a complete buffer to a file descriptor.
0044  *
0045  * @param fd File descriptor
0046  * @param len Number of bytes to write
0047  * @param buffer Buffer to write from
0048  *
0049  * @returns PMIX_SUCCESS upon success.
0050  * @returns PMIX_ERR_IN_ERRNO otherwise.
0051  *
0052  * Loop over writing to the fd until len bytes are written or an error
0053  * occurs.  EAGAIN and EINTR are transparently handled.
0054  */
0055 PMIX_EXPORT pmix_status_t pmix_fd_write(int fd, int len, const void *buffer);
0056 
0057 /**
0058  * Convenience function to set a file descriptor to be close-on-exec.
0059  *
0060  * @param fd File descriptor
0061  *
0062  * @returns PMIX_SUCCESS upon success (or if the system does not
0063  * support close-on-exec behavior).
0064  * @returns PMIX_ERR_IN_ERRNO otherwise.
0065  *
0066  * This is simply a convenience function because there's a few steps
0067  * to setting a file descriptor to be close-on-exec.
0068  */
0069 PMIX_EXPORT pmix_status_t pmix_fd_set_cloexec(int fd);
0070 
0071 /**
0072  * Convenience function to check if fd point to an accessible regular file.
0073  *
0074  * @param fd File descriptor
0075  *
0076  * @returns true if "fd" points to a regular file.
0077  * @returns false otherwise.
0078  */
0079 PMIX_EXPORT bool pmix_fd_is_regular(int fd);
0080 
0081 /**
0082  * Convenience function to check if fd point to an accessible character device.
0083  *
0084  * @param fd File descriptor
0085  *
0086  * @returns true if "fd" points to a regular file.
0087  * @returns false otherwise.
0088  */
0089 PMIX_EXPORT bool pmix_fd_is_chardev(int fd);
0090 
0091 /**
0092  * Convenience function to check if fd point to an accessible block device.
0093  *
0094  * @param fd File descriptor
0095  *
0096  * @returns true if "fd" points to a regular file.
0097  * @returns false otherwise.
0098  */
0099 PMIX_EXPORT bool pmix_fd_is_blkdev(int fd);
0100 
0101 /**
0102  * Close all open sockets other than stdin/out/err prior to
0103  * exec'ing a new binary
0104  */
0105 PMIX_EXPORT void pmix_close_open_file_descriptors(int protected_fd);
0106 
0107 PMIX_EXPORT const char *pmix_fd_get_peer_name(int fd);
0108 
0109 END_C_DECLS
0110 
0111 #endif