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 22 #ifndef PHP_SOCKETS_H 23 #define PHP_SOCKETS_H 24 25 #if HAVE_CONFIG_H 26 # include "config.h" 27 #endif 28 29 #if HAVE_SOCKETS 30 31 #include <php.h> 32 #ifdef PHP_WIN32 33 # include "windows_common.h" 34 #endif 35 36 #define PHP_SOCKETS_VERSION PHP_VERSION 37 38 extern zend_module_entry sockets_module_entry; 39 #define phpext_sockets_ptr &sockets_module_entry 40 41 #ifdef PHP_WIN32 42 #include <Winsock2.h> 43 #else 44 #if HAVE_SYS_SOCKET_H 45 #include <sys/socket.h> 46 #endif 47 #endif 48 49 #ifndef PHP_WIN32 50 typedef int PHP_SOCKET; 51 # define PHP_SOCKETS_API PHPAPI 52 #else 53 # define PHP_SOCKETS_API __declspec(dllexport) 54 typedef SOCKET PHP_SOCKET; 55 #endif 56 57 typedef struct { 58 PHP_SOCKET bsd_socket; 59 int type; 60 int error; 61 int blocking; 62 zval zstream; 63 } php_socket; 64 65 #ifdef PHP_WIN32 66 struct sockaddr_un { 67 short sun_family; 68 char sun_path[108]; 69 }; 70 #endif 71 72 PHP_SOCKETS_API int php_sockets_le_socket(void); 73 PHP_SOCKETS_API php_socket *php_create_socket(void); 74 PHP_SOCKETS_API void php_destroy_socket(zend_resource *rsrc); 75 PHP_SOCKETS_API void php_destroy_sockaddr(zend_resource *rsrc); 76 77 #define php_sockets_le_socket_name "Socket" 78 #define php_sockets_le_addrinfo_name "AddressInfo" 79 80 #define PHP_SOCKET_ERROR(socket, msg, errn) \ 81 do { \ 82 int _err = (errn); /* save value to avoid repeated calls to WSAGetLastError() on Windows */ \ 83 (socket)->error = _err; \ 84 SOCKETS_G(last_error) = _err; \ 85 if (_err != EAGAIN && _err != EWOULDBLOCK && _err != EINPROGRESS) { \ 86 php_error_docref(NULL, E_WARNING, "%s [%d]: %s", msg, _err, sockets_strerror(_err)); \ 87 } \ 88 } while (0) 89 90 ZEND_BEGIN_MODULE_GLOBALS(sockets) 91 int last_error; 92 char *strerror_buf; 93 #ifdef PHP_WIN32 94 uint32_t wsa_child_count; 95 HashTable wsa_info; 96 #endif 97 ZEND_END_MODULE_GLOBALS(sockets) 98 99 ZEND_EXTERN_MODULE_GLOBALS(sockets) 100 #define SOCKETS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(sockets, v) 101 102 enum sockopt_return { 103 SOCKOPT_ERROR, 104 SOCKOPT_CONTINUE, 105 SOCKOPT_SUCCESS 106 }; 107 108 char *sockets_strerror(int error); 109 php_socket *socket_import_file_descriptor(PHP_SOCKET sock); 110 111 #else 112 #define phpext_sockets_ptr NULL 113 #endif 114 115 #if defined(_AIX) && !defined(HAVE_SA_SS_FAMILY) 116 # define ss_family __ss_family 117 #endif 118 119 #endif 120 121 /* 122 * Local variables: 123 * tab-width: 4 124 * c-basic-offset: 4 125 * End: 126 */ 127