fspr_arch_networkio.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef NETWORK_IO_H
  17. #define NETWORK_IO_H
  18. #include "fspr.h"
  19. #include "fspr_private.h"
  20. #include "fspr_network_io.h"
  21. #include "fspr_errno.h"
  22. #include "fspr_general.h"
  23. #include "fspr_lib.h"
  24. #ifndef WAITIO_USES_POLL
  25. #include "fspr_poll.h"
  26. #endif
  27. /* System headers the network I/O library needs */
  28. #if APR_HAVE_SYS_TYPES_H
  29. #include <sys/types.h>
  30. #endif
  31. #if APR_HAVE_SYS_UIO_H
  32. #include <sys/uio.h>
  33. #endif
  34. #ifdef HAVE_SYS_SELECT_H
  35. #include <sys/select.h>
  36. #endif
  37. #if APR_HAVE_ERRNO_H
  38. #include <errno.h>
  39. #endif
  40. #if APR_HAVE_SYS_TIME_H
  41. #include <sys/time.h>
  42. #endif
  43. #if APR_HAVE_UNISTD_H
  44. #include <unistd.h>
  45. #endif
  46. #if APR_HAVE_STRING_H
  47. #include <string.h>
  48. #endif
  49. #if APR_HAVE_NETINET_TCP_H
  50. #include <netinet/tcp.h>
  51. #endif
  52. #if APR_HAVE_NETINET_SCTP_UIO_H
  53. #include <netinet/sctp_uio.h>
  54. #endif
  55. #if APR_HAVE_NETINET_SCTP_H
  56. #include <netinet/sctp.h>
  57. #endif
  58. #if APR_HAVE_NETINET_IN_H
  59. #include <netinet/in.h>
  60. #endif
  61. #if APR_HAVE_ARPA_INET_H
  62. #include <arpa/inet.h>
  63. #endif
  64. #if APR_HAVE_SYS_SOCKET_H
  65. #include <sys/socket.h>
  66. #endif
  67. #if APR_HAVE_SYS_SOCKIO_H
  68. #include <sys/sockio.h>
  69. #endif
  70. #if APR_HAVE_NETDB_H
  71. #include <netdb.h>
  72. #endif
  73. #if APR_HAVE_FCNTL_H
  74. #include <fcntl.h>
  75. #endif
  76. #if APR_HAVE_SYS_SENDFILE_H
  77. #include <sys/sendfile.h>
  78. #endif
  79. #if APR_HAVE_SYS_IOCTL_H
  80. #include <sys/ioctl.h>
  81. #endif
  82. /* End System Headers */
  83. #ifndef HAVE_POLLIN
  84. #define POLLIN 1
  85. #define POLLPRI 2
  86. #define POLLOUT 4
  87. #define POLLERR 8
  88. #define POLLHUP 16
  89. #define POLLNVAL 32
  90. #endif
  91. typedef struct sock_userdata_t sock_userdata_t;
  92. struct sock_userdata_t {
  93. sock_userdata_t *next;
  94. const char *key;
  95. void *data;
  96. };
  97. struct fspr_socket_t {
  98. fspr_pool_t *pool;
  99. int socketdes;
  100. int type;
  101. int protocol;
  102. fspr_sockaddr_t *local_addr;
  103. fspr_sockaddr_t *remote_addr;
  104. fspr_interval_time_t timeout;
  105. #ifndef HAVE_POLL
  106. int connected;
  107. #endif
  108. int local_port_unknown;
  109. int local_interface_unknown;
  110. int remote_addr_unknown;
  111. fspr_int32_t options;
  112. fspr_int32_t inherit;
  113. sock_userdata_t *userdata;
  114. #ifndef WAITIO_USES_POLL
  115. /* if there is a timeout set, then this pollset is used */
  116. fspr_pollset_t *pollset;
  117. #endif
  118. };
  119. const char *fspr_inet_ntop(int af, const void *src, char *dst, fspr_size_t size);
  120. int fspr_inet_pton(int af, const char *src, void *dst);
  121. void fspr_sockaddr_vars_set(fspr_sockaddr_t *, int, fspr_port_t);
  122. #define fspr_is_option_set(skt, option) \
  123. (((skt)->options & (option)) == (option))
  124. #define fspr_set_option(skt, option, on) \
  125. do { \
  126. if (on) \
  127. (skt)->options |= (option); \
  128. else \
  129. (skt)->options &= ~(option); \
  130. } while (0)
  131. #endif /* ! NETWORK_IO_H */