You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.8 KiB

  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: socket.h
  4. // Created: 1/2010
  5. // Author: Vaclav Haisman
  6. //
  7. //
  8. // Copyright (C) 2010, Vaclav Haisman. All rights reserved.
  9. //
  10. // Redistribution and use in source and binary forms, with or without modifica-
  11. // tion, are permitted provided that the following conditions are met:
  12. //
  13. // 1. Redistributions of source code must retain the above copyright notice,
  14. // this list of conditions and the following disclaimer.
  15. //
  16. // 2. Redistributions in binary form must reproduce the above copyright notice,
  17. // this list of conditions and the following disclaimer in the documentation
  18. // and/or other materials provided with the distribution.
  19. //
  20. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  21. // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  25. // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  27. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. /** @file
  31. * This header contains declaration internal to log4cplus. They must never be
  32. * visible from user accesible headers or exported in DLL/shared libray.
  33. */
  34. #ifndef LOG4CPLUS_INTERNAL_SOCKET_H_
  35. #define LOG4CPLUS_INTERNAL_SOCKET_H_
  36. #include <log4cplus/config.hxx>
  37. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  38. #pragma once
  39. #endif
  40. #if ! defined (INSIDE_LOG4CPLUS)
  41. # error "This header must not be be used outside log4cplus' implementation files."
  42. #endif
  43. #if defined(_WIN32)
  44. #include <log4cplus/config/windowsh-inc.h>
  45. #endif
  46. #include <log4cplus/helpers/socket.h>
  47. #include <cerrno>
  48. #ifdef LOG4CPLUS_HAVE_ERRNO_H
  49. #include <errno.h>
  50. #endif
  51. namespace log4cplus {
  52. namespace helpers {
  53. #if defined(_WIN32)
  54. typedef SOCKET os_socket_type;
  55. #else
  56. typedef int os_socket_type;
  57. #endif
  58. os_socket_type const INVALID_OS_SOCKET_VALUE
  59. #if defined(_WIN32)
  60. = INVALID_SOCKET;
  61. #else
  62. = -1;
  63. #endif
  64. static inline
  65. os_socket_type
  66. to_os_socket (SOCKET_TYPE const & x)
  67. {
  68. return static_cast<os_socket_type>(x);
  69. }
  70. static inline
  71. SOCKET_TYPE
  72. to_log4cplus_socket (os_socket_type const & x)
  73. {
  74. return static_cast<SOCKET_TYPE>(x);
  75. }
  76. static inline
  77. void
  78. set_last_socket_error (int err)
  79. {
  80. errno = err;
  81. }
  82. static inline
  83. int
  84. get_last_socket_error ()
  85. {
  86. return errno;
  87. }
  88. } // namespace helpers {
  89. } // namespace log4cplus {
  90. #endif // LOG4CPLUS_INTERNAL_SOCKET_H_