1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #ifndef PHP_SOCKETS_H
23 #define PHP_SOCKETS_H
24
25
26
27 #if HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #if HAVE_SOCKETS
32
33 #include <php.h>
34 #ifdef PHP_WIN32
35 # include "windows_common.h"
36 #endif
37
38 #define PHP_SOCKETS_VERSION PHP_VERSION
39
40 extern zend_module_entry sockets_module_entry;
41 #define phpext_sockets_ptr &sockets_module_entry
42
43 #ifdef PHP_WIN32
44 #include <Winsock2.h>
45 #else
46 #if HAVE_SYS_SOCKET_H
47 #include <sys/socket.h>
48 #endif
49 #endif
50
51 #ifndef PHP_WIN32
52 typedef int PHP_SOCKET;
53 # define PHP_SOCKETS_API PHPAPI
54 #else
55 # define PHP_SOCKETS_API __declspec(dllexport)
56 typedef SOCKET PHP_SOCKET;
57 #endif
58
59 typedef struct {
60 PHP_SOCKET bsd_socket;
61 int type;
62 int error;
63 int blocking;
64 zval zstream;
65 } php_socket;
66
67 #ifdef PHP_WIN32
68 struct sockaddr_un {
69 short sun_family;
70 char sun_path[108];
71 };
72 #endif
73
74 PHP_SOCKETS_API int php_sockets_le_socket(void);
75 PHP_SOCKETS_API php_socket *php_create_socket(void);
76 PHP_SOCKETS_API void php_destroy_socket(zend_resource *rsrc);
77
78 #define php_sockets_le_socket_name "Socket"
79
80 #define PHP_SOCKET_ERROR(socket, msg, errn) \
81 do { \
82 int _err = (errn); \
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 ZEND_END_MODULE_GLOBALS(sockets)
94
95 ZEND_EXTERN_MODULE_GLOBALS(sockets)
96 #define SOCKETS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(sockets, v)
97
98 enum sockopt_return {
99 SOCKOPT_ERROR,
100 SOCKOPT_CONTINUE,
101 SOCKOPT_SUCCESS
102 };
103
104 char *sockets_strerror(int error);
105 php_socket *socket_import_file_descriptor(PHP_SOCKET sock);
106
107 #else
108 #define phpext_sockets_ptr NULL
109 #endif
110
111 #if defined(_AIX) && !defined(HAVE_SA_SS_FAMILY)
112 # define ss_family __ss_family
113 #endif
114
115 #endif
116
117
118
119
120
121
122
123