a2netcompat.h 3.8 KB

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