close-hook.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Hook for making the close() function extensible.
  2. Copyright (C) 2009, 2010 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published
  5. by the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #ifndef CLOSE_HOOK_H
  14. #define CLOSE_HOOK_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /* Currently, this entire code is only needed for the handling of sockets
  19. on native Windows platforms. */
  20. #if WINDOWS_SOCKETS
  21. /* An element of the list of close hooks.
  22. The fields of this structure are considered private. */
  23. struct close_hook
  24. {
  25. /* Doubly linked list. */
  26. struct close_hook *private_next;
  27. struct close_hook *private_prev;
  28. /* Function that treats the types of FD that it knows about and calls
  29. execute_close_hooks (FD, REMAINING_LIST) as a fallback. */
  30. int (*private_fn) (int fd, const struct close_hook *remaining_list);
  31. };
  32. /* This type of function closes FD, applying special knowledge for the FD
  33. types it knows about, and calls execute_close_hooks (FD, REMAINING_LIST)
  34. for the other FD types. */
  35. typedef int (*close_hook_fn) (int fd, const struct close_hook *remaining_list);
  36. /* Execute the close hooks in REMAINING_LIST.
  37. Return 0 or -1, like close() would do. */
  38. extern int execute_close_hooks (int fd, const struct close_hook *remaining_list);
  39. /* Execute all close hooks.
  40. Return 0 or -1, like close() would do. */
  41. extern int execute_all_close_hooks (int fd);
  42. /* Add a function to the list of close hooks.
  43. The LINK variable points to a piece of memory which is guaranteed to be
  44. accessible until the corresponding call to unregister_close_hook. */
  45. extern void register_close_hook (close_hook_fn hook, struct close_hook *link);
  46. /* Removes a function from the list of close hooks. */
  47. extern void unregister_close_hook (struct close_hook *link);
  48. #endif
  49. #ifdef __cplusplus
  50. }
  51. #endif
  52. #endif /* CLOSE_HOOK_H */