fd.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 __UTIL_IO_FD_H
  15. #define __UTIL_IO_FD_H 1
  16. #include <unistd.h>
  17. /**
  18. * @file fd.h
  19. * @short Wrappers around common unix fd manipulation functions.
  20. */
  21. namespace isc {
  22. namespace util {
  23. namespace io {
  24. /*
  25. * \short write() that writes everything.
  26. * Wrapper around write(). The difference is, it never writes less data
  27. * and looks successfull (eg. it blocks until all data are written).
  28. * Retries on signals.
  29. *
  30. * \return True if sucessfull, false otherwise. The errno variable is left
  31. * intact.
  32. * \param fd Where to write.
  33. * \param data The buffer to write.
  34. * \param length How much data is there to write.
  35. */
  36. bool
  37. write_data(const int fd, const void *data, const size_t length);
  38. /*
  39. * \short read() that reads everything.
  40. * Wrapper around read(). It does not do short reads, if it returns less,
  41. * it means there was EOF. It retries on signals.
  42. *
  43. * \return Number of bytes read or -1 on error.
  44. * \param fd Where to read data from.
  45. * \param data Where to put the data.
  46. * \param length How many of them.
  47. */
  48. ssize_t
  49. read_data(const int fd, void *buffer, const size_t length);
  50. }
  51. }
  52. }
  53. #endif // __UTIL_IO_FD_H