2010-07-20 23:53:49 +04:00
|
|
|
/*
|
2014-04-24 17:20:32 +04:00
|
|
|
* Copyright (c) 2008-2014 Cisco Systems, Inc. All rights reserved.
|
2010-07-20 23:53:49 +04:00
|
|
|
* Copyright (c) 2009 Sandia National Laboratories. All rights reserved.
|
|
|
|
*
|
|
|
|
* $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);
|
|
|
|
|
2010-07-21 15:05:08 +04:00
|
|
|
END_C_DECLS
|
|
|
|
|
2010-07-20 23:53:49 +04:00
|
|
|
#endif
|