2010-07-20 23:53:49 +04:00
|
|
|
/*
|
2018-03-21 23:48:51 +03:00
|
|
|
* Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved
|
2010-07-20 23:53:49 +04:00
|
|
|
* Copyright (c) 2009 Sandia National Laboratories. All rights reserved.
|
2017-06-29 02:06:33 +03:00
|
|
|
* Copyright (c) 2017 Mellanox Technologies. All rights reserved.
|
2010-07-20 23:53:49 +04:00
|
|
|
*
|
|
|
|
* $COPYRIGHT$
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2010-07-20 23:53:49 +04:00
|
|
|
* Additional copyrights may follow
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2010-07-20 23:53:49 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* @file */
|
|
|
|
|
|
|
|
#ifndef OPAL_UTIL_FD_H_
|
|
|
|
#define OPAL_UTIL_FD_H_
|
|
|
|
|
|
|
|
#include "opal_config.h"
|
|
|
|
|
2010-07-21 15:05:08 +04:00
|
|
|
BEGIN_C_DECLS
|
|
|
|
|
2010-07-20 23:53:49 +04:00
|
|
|
/**
|
|
|
|
* Read a complete buffer from a file descriptor.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor
|
|
|
|
* @param len Number of bytes to read
|
|
|
|
* @param buffer Pre-allocated buffer (large enough to hold len bytes)
|
|
|
|
*
|
|
|
|
* @returns OPAL_SUCCESS upon success.
|
2010-08-24 23:07:04 +04:00
|
|
|
* @returns OPAL_ERR_TIMEOUT if the fd closes before reading the full amount.
|
2010-07-20 23:53:49 +04:00
|
|
|
* @returns OPAL_ERR_IN_ERRNO otherwise.
|
|
|
|
*
|
|
|
|
* Loop over reading from the fd until len bytes are read or an error
|
|
|
|
* occurs. EAGAIN and EINTR are transparently handled.
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC int opal_fd_read(int fd, int len, void *buffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a complete buffer to a file descriptor.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor
|
|
|
|
* @param len Number of bytes to write
|
|
|
|
* @param buffer Buffer to write from
|
|
|
|
*
|
|
|
|
* @returns OPAL_SUCCESS upon success.
|
|
|
|
* @returns OPAL_ERR_IN_ERRNO otherwise.
|
|
|
|
*
|
|
|
|
* Loop over writing to the fd until len bytes are written or an error
|
|
|
|
* occurs. EAGAIN and EINTR are transparently handled.
|
|
|
|
*/
|
2010-07-21 15:01:16 +04:00
|
|
|
OPAL_DECLSPEC int opal_fd_write(int fd, int len, const void *buffer);
|
2010-07-20 23:53:49 +04:00
|
|
|
|
2014-04-24 17:04:49 +04:00
|
|
|
/**
|
|
|
|
* Convenience function to set a file descriptor to be close-on-exec.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor
|
|
|
|
*
|
|
|
|
* @returns OPAL_SUCCESS upon success (or if the system does not
|
|
|
|
* support close-on-exec behavior).
|
|
|
|
* @returns OPAL_ERR_IN_ERRNO otherwise.
|
|
|
|
*
|
|
|
|
* This is simply a convenience function because there's a few steps
|
|
|
|
* to setting a file descriptor to be close-on-exec.
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC int opal_fd_set_cloexec(int fd);
|
|
|
|
|
2017-06-29 02:06:33 +03:00
|
|
|
/**
|
|
|
|
* Convenience function to check if fd point to an accessible regular file.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor
|
|
|
|
*
|
|
|
|
* @returns true if "fd" points to a regular file.
|
|
|
|
* @returns false otherwise.
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC bool opal_fd_is_regular(int fd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function to check if fd point to an accessible character device.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor
|
|
|
|
*
|
|
|
|
* @returns true if "fd" points to a regular file.
|
|
|
|
* @returns false otherwise.
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC bool opal_fd_is_chardev(int fd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function to check if fd point to an accessible block device.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor
|
|
|
|
*
|
|
|
|
* @returns true if "fd" points to a regular file.
|
|
|
|
* @returns false otherwise.
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC bool opal_fd_is_blkdev(int fd);
|
|
|
|
|
2018-03-21 23:48:51 +03:00
|
|
|
/**
|
|
|
|
* Convenience function to get a string name of the peer on the other
|
|
|
|
* end of this internet socket.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor of an AF_INET/AF_INET6 socket
|
|
|
|
*
|
|
|
|
* @returns resolvable IP name, or "a.b.c.d". This string must be freed by the caller.
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC const char *opal_fd_get_peer_name(int fd);
|
2017-06-29 02:06:33 +03:00
|
|
|
|
2010-07-21 15:05:08 +04:00
|
|
|
END_C_DECLS
|
|
|
|
|
2010-07-20 23:53:49 +04:00
|
|
|
#endif
|