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 "fspr_arch_networkio.h"
  17. #include "fspr_network_io.h"
  18. #include "fspr_portable.h"
  19. #include "fspr_general.h"
  20. #include "fspr_lib.h"
  21. static int os2_socket_init(int, int ,int);
  22. int (*fspr_os2_socket)(int, int, int) = os2_socket_init;
  23. int (*fspr_os2_select)(int *, int, int, int, long) = NULL;
  24. int (*fspr_os2_sock_errno)() = NULL;
  25. int (*fspr_os2_accept)(int, struct sockaddr *, int *) = NULL;
  26. int (*fspr_os2_bind)(int, struct sockaddr *, int) = NULL;
  27. int (*fspr_os2_connect)(int, struct sockaddr *, int) = NULL;
  28. int (*fspr_os2_getpeername)(int, struct sockaddr *, int *) = NULL;
  29. int (*fspr_os2_getsockname)(int, struct sockaddr *, int *) = NULL;
  30. int (*fspr_os2_getsockopt)(int, int, int, char *, int *) = NULL;
  31. int (*fspr_os2_ioctl)(int, int, caddr_t, int) = NULL;
  32. int (*fspr_os2_listen)(int, int) = NULL;
  33. int (*fspr_os2_recv)(int, char *, int, int) = NULL;
  34. int (*fspr_os2_send)(int, const char *, int, int) = NULL;
  35. int (*fspr_os2_setsockopt)(int, int, int, char *, int) = NULL;
  36. int (*fspr_os2_shutdown)(int, int) = NULL;
  37. int (*fspr_os2_soclose)(int) = NULL;
  38. int (*fspr_os2_writev)(int, struct iovec *, int) = NULL;
  39. int (*fspr_os2_sendto)(int, const char *, int, int, const struct sockaddr *, int);
  40. int (*fspr_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 (fspr_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", &fspr_os2_socket);
  52. if (!rc)
  53. rc = DosQueryProcAddr(hSO32DLL, 0, "SELECT", &fspr_os2_select);
  54. if (!rc)
  55. rc = DosQueryProcAddr(hSO32DLL, 0, "SOCK_ERRNO", &fspr_os2_sock_errno);
  56. if (!rc)
  57. rc = DosQueryProcAddr(hSO32DLL, 0, "ACCEPT", &fspr_os2_accept);
  58. if (!rc)
  59. rc = DosQueryProcAddr(hSO32DLL, 0, "BIND", &fspr_os2_bind);
  60. if (!rc)
  61. rc = DosQueryProcAddr(hSO32DLL, 0, "CONNECT", &fspr_os2_connect);
  62. if (!rc)
  63. rc = DosQueryProcAddr(hSO32DLL, 0, "GETPEERNAME", &fspr_os2_getpeername);
  64. if (!rc)
  65. rc = DosQueryProcAddr(hSO32DLL, 0, "GETSOCKNAME", &fspr_os2_getsockname);
  66. if (!rc)
  67. rc = DosQueryProcAddr(hSO32DLL, 0, "GETSOCKOPT", &fspr_os2_getsockopt);
  68. if (!rc)
  69. rc = DosQueryProcAddr(hSO32DLL, 0, "IOCTL", &fspr_os2_ioctl);
  70. if (!rc)
  71. rc = DosQueryProcAddr(hSO32DLL, 0, "LISTEN", &fspr_os2_listen);
  72. if (!rc)
  73. rc = DosQueryProcAddr(hSO32DLL, 0, "RECV", &fspr_os2_recv);
  74. if (!rc)
  75. rc = DosQueryProcAddr(hSO32DLL, 0, "SEND", &fspr_os2_send);
  76. if (!rc)
  77. rc = DosQueryProcAddr(hSO32DLL, 0, "SETSOCKOPT", &fspr_os2_setsockopt);
  78. if (!rc)
  79. rc = DosQueryProcAddr(hSO32DLL, 0, "SHUTDOWN", &fspr_os2_shutdown);
  80. if (!rc)
  81. rc = DosQueryProcAddr(hSO32DLL, 0, "SOCLOSE", &fspr_os2_soclose);
  82. if (!rc)
  83. rc = DosQueryProcAddr(hSO32DLL, 0, "WRITEV", &fspr_os2_writev);
  84. if (!rc)
  85. rc = DosQueryProcAddr(hSO32DLL, 0, "SENDTO", &fspr_os2_sendto);
  86. if (!rc)
  87. rc = DosQueryProcAddr(hSO32DLL, 0, "RECVFROM", &fspr_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 fspr_os2_socket(domain, type, protocol);
  99. return rc;
  100. }