1 // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC") 2 // 3 // This Source Code Form is subject to the terms of the Mozilla Public 4 // License, v. 2.0. If a copy of the MPL was not distributed with this 5 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7 #ifndef FD_SHARE_H_ 8 #define FD_SHARE_H_ 9 10 /** 11 * \file fd_share.h 12 * \short Support to transfer file descriptors between processes. 13 * \todo This interface is very C-ish. Should we have some kind of exceptions? 14 */ 15 16 namespace isc { 17 namespace util { 18 namespace io { 19 20 const int FD_SYSTEM_ERROR = -2; 21 const int FD_OTHER_ERROR = -1; 22 23 /** 24 * \short Receives a file descriptor. 25 * This receives a file descriptor sent over an unix domain socket. This 26 * is the counterpart of send_fd(). 27 * 28 * \return FD_SYSTEM_ERROR when there's an error at the operating system 29 * level (such as a system call failure). The global 'errno' variable 30 * indicates the specific error. FD_OTHER_ERROR when there's a different 31 * error. 32 * 33 * \param sock The unix domain socket to read from. Tested and it does 34 * not work with a pipe. 35 */ 36 int recv_fd(const int sock); 37 38 /** 39 * \short Sends a file descriptor. 40 * This sends a file descriptor over an unix domain socket. This is the 41 * counterpart of recv_fd(). 42 * 43 * \return FD_SYSTEM_ERROR when there's an error at the operating system 44 * level (such as a system call failure). The global 'errno' variable 45 * indicates the specific error. 46 * \param sock The unix domain socket to send to. Tested and it does not 47 * work with a pipe. 48 * \param fd The file descriptor to send. It should work with any valid 49 * file descriptor. 50 */ 51 int send_fd(const int sock, const int fd); 52 53 } // End for namespace io 54 } // End for namespace util 55 } // End for namespace isc 56 57 #endif 58 59 // Local Variables: 60 // mode: c++ 61 // End: 62