a2netcompat.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * aria2 - The high speed download utility
  3. *
  4. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. * In addition, as a special exception, the copyright holders give
  21. * permission to link the code of portions of this program with the
  22. * OpenSSL library under certain conditions as described in each
  23. * individual source file, and distribute linked combinations
  24. * including the two.
  25. * You must obey the GNU General Public License in all respects
  26. * for all of the code used other than OpenSSL. If you modify
  27. * file(s) with this exception, you may extend this exception to your
  28. * version of the file(s), but you are not obligated to do so. If you
  29. * do not wish to do so, delete this exception statement from your
  30. * version. If you delete this exception statement from all source
  31. * files in the program, then also delete it here.
  32. */
  33. /* copyright --> */
  34. #ifndef D_A2NETCOMPAT_H
  35. #define D_A2NETCOMPAT_H
  36. #include "a2io.h"
  37. #ifdef __MINGW32__
  38. #ifdef HAVE_WS2TCPIP_H
  39. #include <ws2tcpip.h>
  40. #endif // HAVE_WS2TCPIP_H
  41. #endif // __MINGW32__
  42. #ifdef __MINGW32__
  43. #define a2_sockopt_t char *
  44. #ifndef HAVE_GETADDRINFO
  45. #define HAVE_GETADDRINFO
  46. #endif // !HAVE_GETADDRINFO
  47. #undef HAVE_GAI_STRERROR
  48. #undef gai_strerror
  49. #else
  50. #define a2_sockopt_t void *
  51. #endif // __MINGW32__
  52. #ifdef HAVE_NETDB_H
  53. #include <netdb.h>
  54. #endif // HAVE_NETDB_H
  55. #ifdef HAVE_SYS_SOCKET_H
  56. #include <sys/socket.h>
  57. #endif // HAVE_SYS_SOCKET_H
  58. #ifdef HAVE_NETINET_IN_H
  59. #include <netinet/in.h>
  60. #endif // HAVE_NETINET_IN_H
  61. #ifdef HAVE_NETINET_TCP_H
  62. #include <netinet/tcp.h>
  63. #endif // HAVE_NETINET_TCP_H
  64. #ifdef HAVE_ARPA_INET_H
  65. #include <arpa/inet.h>
  66. #endif // HAVE_ARPA_INET_H
  67. #ifdef HAVE_NETINET_IN_H
  68. #include <netinet/in.h>
  69. #endif // HAVE_NETINET_IN_H
  70. #ifdef HAVE_SYS_UIO_H
  71. #include <sys/uio.h>
  72. #endif // HAVE_SYS_UIO_H
  73. #ifndef HAVE_GETADDRINFO
  74. #include "getaddrinfo.h"
  75. #define HAVE_GAI_STRERROR
  76. #endif // HAVE_GETADDRINFO
  77. #ifndef HAVE_GAI_STRERROR
  78. #include "gai_strerror.h"
  79. #endif // HAVE_GAI_STRERROR
  80. #include <string>
  81. #ifdef HAVE_WINSOCK2_H
  82. #define sock_t SOCKET
  83. #else
  84. #define sock_t int
  85. #endif
  86. #ifndef AI_ADDRCONFIG
  87. #define AI_ADDRCONFIG 0
  88. #endif // !AI_ADDRCONFIG
  89. #define DEFAULT_AI_FLAGS AI_ADDRCONFIG
  90. #ifdef __MINGW32__
  91. #ifndef SHUT_WR
  92. #define SHUT_WR SD_SEND
  93. #endif // !SHUT_WR
  94. #endif // __MINGW32__
  95. union sockaddr_union {
  96. sockaddr sa;
  97. sockaddr_storage storage;
  98. sockaddr_in6 in6;
  99. sockaddr_in in;
  100. };
  101. struct SockAddr {
  102. sockaddr_union su;
  103. socklen_t suLength;
  104. };
  105. // Human readable address, family and port. In other words, addr is
  106. // text name, usually obtained from getnameinfo(3). The family field
  107. // is the protocol family if it is known when generating this object.
  108. // If it is unknown, this is AF_UNSPEC.
  109. struct Endpoint {
  110. std::string addr;
  111. int family;
  112. uint16_t port;
  113. };
  114. #define A2_DEFAULT_IOV_MAX 128
  115. #if defined(IOV_MAX) && IOV_MAX < A2_DEFAULT_IOV_MAX
  116. #define A2_IOV_MAX IOV_MAX
  117. #else
  118. #define A2_IOV_MAX A2_DEFAULT_IOV_MAX
  119. #endif
  120. #ifdef __MINGW32__
  121. typedef WSABUF a2iovec;
  122. #define A2IOVEC_BASE buf
  123. #define A2IOVEC_LEN len
  124. #else // !__MINGW32__
  125. typedef struct iovec a2iovec;
  126. #define A2IOVEC_BASE iov_base
  127. #define A2IOVEC_LEN iov_len
  128. #endif // !__MINGW32__
  129. #endif // D_A2NETCOMPAT_H