sockets.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* sockets.h - wrappers for Windows socket functions
  2. Copyright (C) 2008-2023 Free Software Foundation, Inc.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser 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 */