os2calls.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include "apr_arch_networkio.h"
  17. #include "apr_network_io.h"
  18. #include "apr_portable.h"
  19. #include "apr_general.h"
  20. #include "apr_lib.h"
  21. static int os2_socket_init(int, int ,int);
  22. int (*apr_os2_socket)(int, int, int) = os2_socket_init;
  23. int (*apr_os2_select)(int *, int, int, int, long) = NULL;
  24. int (*apr_os2_sock_errno)() = NULL;
  25. int (*apr_os2_accept)(int, struct sockaddr *, int *) = NULL;
  26. int (*apr_os2_bind)(int, struct sockaddr *, int) = NULL;
  27. int (*apr_os2_connect)(int, struct sockaddr *, int) = NULL;
  28. int (*apr_os2_getpeername)(int, struct sockaddr *, int *) = NULL;
  29. int (*apr_os2_getsockname)(int, struct sockaddr *, int *) = NULL;
  30. int (*apr_os2_getsockopt)(int, int, int, char *, int *) = NULL;
  31. int (*apr_os2_ioctl)(int, int, caddr_t, int) = NULL;
  32. int (*apr_os2_listen)(int, int) = NULL;
  33. int (*apr_os2_recv)(int, char *, int, int) = NULL;
  34. int (*apr_os2_send)(int, const char *, int, int) = NULL;
  35. int (*apr_os2_setsockopt)(int, int, int, char *, int) = NULL;
  36. int (*apr_os2_shutdown)(int, int) = NULL;
  37. int (*apr_os2_soclose)(int) = NULL;
  38. int (*apr_os2_writev)(int, struct iovec *, int) = NULL;
  39. int (*apr_os2_sendto)(int, const char *, int, int, const struct sockaddr *, int);
  40. int (*apr_os2_recvfrom)(int, char *, int, int, struct sockaddr *, int *);
  41. static HMODULE hSO32DLL;
  42. static int os2_fn_link()
  43. {
  44. DosEnterCritSec(); /* Stop two threads doing this at the same time */
  45. if (apr_os2_socket == os2_socket_init) {
  46. ULONG rc;
  47. char errorstr[200];
  48. rc = DosLoadModule(errorstr, sizeof(errorstr), "SO32DLL", &hSO32DLL);
  49. if (rc)
  50. return APR_OS2_STATUS(rc);
  51. rc = DosQueryProcAddr(hSO32DLL, 0, "SOCKET", &apr_os2_socket);
  52. if (!rc)
  53. rc = DosQueryProcAddr(hSO32DLL, 0, "SELECT", &apr_os2_select);
  54. if (!rc)
  55. rc = DosQueryProcAddr(hSO32DLL, 0, "SOCK_ERRNO", &apr_os2_sock_errno);
  56. if (!rc)
  57. rc = DosQueryProcAddr(hSO32DLL, 0, "ACCEPT", &apr_os2_accept);
  58. if (!rc)
  59. rc = DosQueryProcAddr(hSO32DLL, 0, "BIND", &apr_os2_bind);
  60. if (!rc)
  61. rc = DosQueryProcAddr(hSO32DLL, 0, "CONNECT", &apr_os2_connect);
  62. if (!rc)
  63. rc = DosQueryProcAddr(hSO32DLL, 0, "GETPEERNAME", &apr_os2_getpeername);
  64. if (!rc)
  65. rc = DosQueryProcAddr(hSO32DLL, 0, "GETSOCKNAME", &apr_os2_getsockname);
  66. if (!rc)
  67. rc = DosQueryProcAddr(hSO32DLL, 0, "GETSOCKOPT", &apr_os2_getsockopt);
  68. if (!rc)
  69. rc = DosQueryProcAddr(hSO32DLL, 0, "IOCTL", &apr_os2_ioctl);
  70. if (!rc)
  71. rc = DosQueryProcAddr(hSO32DLL, 0, "LISTEN", &apr_os2_listen);
  72. if (!rc)
  73. rc = DosQueryProcAddr(hSO32DLL, 0, "RECV", &apr_os2_recv);
  74. if (!rc)
  75. rc = DosQueryProcAddr(hSO32DLL, 0, "SEND", &apr_os2_send);
  76. if (!rc)
  77. rc = DosQueryProcAddr(hSO32DLL, 0, "SETSOCKOPT", &apr_os2_setsockopt);
  78. if (!rc)
  79. rc = DosQueryProcAddr(hSO32DLL, 0, "SHUTDOWN", &apr_os2_shutdown);
  80. if (!rc)
  81. rc = DosQueryProcAddr(hSO32DLL, 0, "SOCLOSE", &apr_os2_soclose);
  82. if (!rc)
  83. rc = DosQueryProcAddr(hSO32DLL, 0, "WRITEV", &apr_os2_writev);
  84. if (!rc)
  85. rc = DosQueryProcAddr(hSO32DLL, 0, "SENDTO", &apr_os2_sendto);
  86. if (!rc)
  87. rc = DosQueryProcAddr(hSO32DLL, 0, "RECVFROM", &apr_os2_recvfrom);
  88. if (rc)
  89. return APR_OS2_STATUS(rc);
  90. }
  91. DosExitCritSec();
  92. return APR_SUCCESS;
  93. }
  94. static int os2_socket_init(int domain, int type, int protocol)
  95. {
  96. int rc = os2_fn_link();
  97. if (rc == APR_SUCCESS)
  98. return apr_os2_socket(domain, type, protocol);
  99. return rc;
  100. }