fd_share.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef FD_SHARE_H_
  15. #define FD_SHARE_H_
  16. /**
  17. * \file fd_share.h
  18. * \short Support to transfer file descriptors between processes.
  19. * \todo This interface is very C-ish. Should we have some kind of exceptions?
  20. */
  21. namespace isc {
  22. namespace util {
  23. namespace io {
  24. const int FD_COMM_ERROR = -2;
  25. const int FD_OTHER_ERROR = -1;
  26. /**
  27. * \short Receives a file descriptor.
  28. * This receives a file descriptor sent over an unix domain socket. This
  29. * is the counterpart of send_fd().
  30. *
  31. * \return FD_COMM_ERROR when there's error receiving the socket, FD_OTHER_ERROR
  32. * when there's a different error.
  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. * \short Sends a file descriptor.
  39. * This sends a file descriptor over an unix domain socket. This is the
  40. * counterpart of recv_fd().
  41. *
  42. * \return FD_COMM_ERROR when there's error sending the socket, FD_OTHER_ERROR
  43. * for all other possible errors. The global 'errno' variable indicates
  44. * the corresponding system error.
  45. * \param sock The unix domain socket to send to. Tested and it does not
  46. * work with a pipe.
  47. * \param fd The file descriptor to send. It should work with any valid
  48. * file descriptor.
  49. */
  50. int send_fd(const int sock, const int fd);
  51. } // End for namespace io
  52. } // End for namespace util
  53. } // End for namespace isc
  54. #endif
  55. // Local Variables:
  56. // mode: c++
  57. // End: