sockets.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* sockets.h - wrappers for Windows socket functions
  2. Copyright (C) 2008-2021 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. 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
  10. GNU 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 <https://www.gnu.org/licenses/>. */
  13. /* Written by Simon Josefsson */
  14. #ifndef SOCKETS_H
  15. #define SOCKETS_H 1
  16. #define SOCKETS_1_0 0x0001
  17. #define SOCKETS_1_1 0x0101
  18. #define SOCKETS_2_0 0x0002
  19. #define SOCKETS_2_1 0x0102
  20. #define SOCKETS_2_2 0x0202
  21. int gl_sockets_startup (int version)
  22. #ifndef WINDOWS_SOCKETS
  23. _GL_ATTRIBUTE_CONST
  24. #endif
  25. ;
  26. int gl_sockets_cleanup (void)
  27. #ifndef WINDOWS_SOCKETS
  28. _GL_ATTRIBUTE_CONST
  29. #endif
  30. ;
  31. /* This function is useful it you create a socket using gnulib's
  32. Winsock wrappers but needs to pass on the socket handle to some
  33. other library that only accepts sockets. */
  34. #ifdef WINDOWS_SOCKETS
  35. # include <sys/socket.h>
  36. # if GNULIB_MSVC_NOTHROW
  37. # include "msvc-nothrow.h"
  38. # else
  39. # include <io.h>
  40. # endif
  41. static inline SOCKET
  42. gl_fd_to_handle (int fd)
  43. {
  44. return _get_osfhandle (fd);
  45. }
  46. #else
  47. # define gl_fd_to_handle(x) (x)
  48. #endif /* WINDOWS_SOCKETS */
  49. #endif /* SOCKETS_H */