php_sockets.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Chris Vandomelen <chrisv@b0rked.dhs.org> |
  16. | Sterling Hughes <sterling@php.net> |
  17. | |
  18. | WinSock: Daniel Beulshausen <daniel@php4win.de> |
  19. +----------------------------------------------------------------------+
  20. */
  21. #ifndef PHP_SOCKETS_H
  22. #define PHP_SOCKETS_H
  23. #if HAVE_CONFIG_H
  24. # include "config.h"
  25. #endif
  26. #if HAVE_SOCKETS
  27. #include <php.h>
  28. #ifdef PHP_WIN32
  29. # include "windows_common.h"
  30. #endif
  31. #define PHP_SOCKETS_VERSION PHP_VERSION
  32. extern zend_module_entry sockets_module_entry;
  33. #define phpext_sockets_ptr &sockets_module_entry
  34. #ifdef PHP_WIN32
  35. #include <Winsock2.h>
  36. #else
  37. #if HAVE_SYS_SOCKET_H
  38. #include <sys/socket.h>
  39. #endif
  40. #endif
  41. #ifndef PHP_WIN32
  42. typedef int PHP_SOCKET;
  43. # define PHP_SOCKETS_API PHPAPI
  44. #else
  45. # define PHP_SOCKETS_API __declspec(dllexport)
  46. typedef SOCKET PHP_SOCKET;
  47. #endif
  48. typedef struct {
  49. PHP_SOCKET bsd_socket;
  50. int type;
  51. int error;
  52. int blocking;
  53. zval zstream;
  54. } php_socket;
  55. #ifdef PHP_WIN32
  56. struct sockaddr_un {
  57. short sun_family;
  58. char sun_path[108];
  59. };
  60. #endif
  61. PHP_SOCKETS_API int php_sockets_le_socket(void);
  62. PHP_SOCKETS_API php_socket *php_create_socket(void);
  63. PHP_SOCKETS_API void php_destroy_socket(zend_resource *rsrc);
  64. PHP_SOCKETS_API void php_destroy_sockaddr(zend_resource *rsrc);
  65. #define php_sockets_le_socket_name "Socket"
  66. #define php_sockets_le_addrinfo_name "AddressInfo"
  67. #define PHP_SOCKET_ERROR(socket, msg, errn) \
  68. do { \
  69. int _err = (errn); /* save value to avoid repeated calls to WSAGetLastError() on Windows */ \
  70. (socket)->error = _err; \
  71. SOCKETS_G(last_error) = _err; \
  72. if (_err != EAGAIN && _err != EWOULDBLOCK && _err != EINPROGRESS) { \
  73. php_error_docref(NULL, E_WARNING, "%s [%d]: %s", msg, _err, sockets_strerror(_err)); \
  74. } \
  75. } while (0)
  76. ZEND_BEGIN_MODULE_GLOBALS(sockets)
  77. int last_error;
  78. char *strerror_buf;
  79. #ifdef PHP_WIN32
  80. uint32_t wsa_child_count;
  81. HashTable wsa_info;
  82. #endif
  83. ZEND_END_MODULE_GLOBALS(sockets)
  84. ZEND_EXTERN_MODULE_GLOBALS(sockets)
  85. #define SOCKETS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(sockets, v)
  86. enum sockopt_return {
  87. SOCKOPT_ERROR,
  88. SOCKOPT_CONTINUE,
  89. SOCKOPT_SUCCESS
  90. };
  91. char *sockets_strerror(int error);
  92. php_socket *socket_import_file_descriptor(PHP_SOCKET sock);
  93. #else
  94. #define phpext_sockets_ptr NULL
  95. #endif
  96. #if defined(_AIX) && !defined(HAVE_SA_SS_FAMILY)
  97. # define ss_family __ss_family
  98. #endif
  99. #endif
  100. /*
  101. * Local variables:
  102. * tab-width: 4
  103. * c-basic-offset: 4
  104. * End:
  105. */