Skip to content

Commit af1b90d

Browse files
committed
Fix bug and hopefully build on WinSDK 6.1
There build was failing on rmtools on the sockets extension for two reasons: 1. IPV6_TCLASS and IPV6_RECVTCLASS not being defined. These are probably recent additions to SDK. Windows 7 doesn't event seem to have complete support for IPV6_TCLASS, not accepting in WSASendMsg(). The parts that needed this constant were not guarded by #ifdefs. They are now. 2. The constants EWOULDBLOCK and EINPROGRESS not being defined. These were only defined in php_network.h, outside of the extension, and not all source files included this header. Nevertheless, a macro defined in php_sockets.h needed these constants. When this macro was used in files that did not include php_network.h, the compilation would fail. Surprisingly, the build did not fail when using the 7.1 Windows SDK (more likely, the CRT headers used in VC10), as somehow errno.h was being included through some other standard header. This would make the constant EWOULDBLOCK defined; however, it would be defined to the wrong value. In the winsock context, WSAEWOULDBLOCK should be used instead. Because we have difficulty using Windows-only constants in the code, we (re)define EWOULDBLOCK to WSAEWOULDBLOCK. This has the obvious disavantage we may miss problems like this again in the future.
1 parent 6ba5d0a commit af1b90d

File tree

3 files changed

+94
-10
lines changed

3 files changed

+94
-10
lines changed

ext/sockets/php_sockets.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#if HAVE_SOCKETS
2828

2929
#include <php.h>
30+
#ifdef PHP_WIN32
31+
# include "windows_common.h"
32+
#endif
3033

3134
extern zend_module_entry sockets_module_entry;
3235
#define phpext_sockets_ptr &sockets_module_entry

ext/sockets/sendrecvmsg.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ static void init_ancillary_registry(void)
115115
to_zval_read_int, IPPROTO_IPV6, IPV6_HOPLIMIT);
116116
#endif
117117

118+
#ifdef IPV6_TCLASS
118119
PUT_ENTRY(sizeof(int), 0, 0, from_zval_write_int,
119120
to_zval_read_int, IPPROTO_IPV6, IPV6_TCLASS);
121+
#endif
120122

121123
#ifdef SO_PASSCRED
122124
PUT_ENTRY(sizeof(struct ucred), 0, 0, from_zval_write_ucred,
@@ -416,14 +418,16 @@ void php_socket_sendrecvmsg_init(INIT_FUNC_ARGS)
416418
REGISTER_LONG_CONSTANT("IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, CONST_CS | CONST_PERSISTENT);
417419
REGISTER_LONG_CONSTANT("IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, CONST_CS | CONST_PERSISTENT);
418420
*/
421+
#ifdef IPV6_RECVTCLASS
419422
REGISTER_LONG_CONSTANT("IPV6_RECVTCLASS", IPV6_RECVTCLASS, CONST_CS | CONST_PERSISTENT);
423+
REGISTER_LONG_CONSTANT("IPV6_TCLASS", IPV6_TCLASS, CONST_CS | CONST_PERSISTENT);
424+
#endif
420425

421426
/*
422427
REGISTER_LONG_CONSTANT("IPV6_RTHDR", IPV6_RTHDR, CONST_CS | CONST_PERSISTENT);
423428
REGISTER_LONG_CONSTANT("IPV6_HOPOPTS", IPV6_HOPOPTS, CONST_CS | CONST_PERSISTENT);
424429
REGISTER_LONG_CONSTANT("IPV6_DSTOPTS", IPV6_DSTOPTS, CONST_CS | CONST_PERSISTENT);
425430
*/
426-
REGISTER_LONG_CONSTANT("IPV6_TCLASS", IPV6_TCLASS, CONST_CS | CONST_PERSISTENT);
427431

428432
#ifdef SCM_RIGHTS
429433
REGISTER_LONG_CONSTANT("SCM_RIGHTS", SCM_RIGHTS, CONST_CS | CONST_PERSISTENT);

ext/sockets/windows_common.h

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@
2424
#define HAVE_IF_NAMETOINDEX 1
2525

2626
#define IS_INVALID_SOCKET(a) (a->bsd_socket == INVALID_SOCKET)
27-
#ifdef EPROTONOSUPPORT
28-
# undef EPROTONOSUPPORT
29-
#endif
30-
#ifdef ECONNRESET
31-
# undef ECONNRESET
32-
#endif
33-
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
34-
#define ECONNRESET WSAECONNRESET
27+
3528
#ifdef errno
3629
# undef errno
3730
#endif
@@ -40,4 +33,88 @@
4033
#define set_errno(a) WSASetLastError(a)
4134
#define close(a) closesocket(a)
4235

43-
#endif
36+
#ifdef ENETUNREACH /* errno.h probably included */
37+
# undef EWOULDBLOCK
38+
# undef EINPROGRESS
39+
# undef EALREADY
40+
# undef ENOTSOCK
41+
# undef EDESTADDRREQ
42+
# undef EMSGSIZE
43+
# undef EPROTOTYPE
44+
# undef ENOPROTOOPT
45+
# undef EPROTONOSUPPORT
46+
# undef ESOCKTNOSUPPORT
47+
# undef EOPNOTSUPP
48+
# undef EPFNOSUPPORT
49+
# undef EAFNOSUPPORT
50+
# undef EADDRINUSE
51+
# undef EADDRNOTAVAIL
52+
# undef ENETDOWN
53+
# undef ENETUNREACH
54+
# undef ENETRESET
55+
# undef ECONNABORTED
56+
# undef ECONNRESET
57+
# undef ENOBUFS
58+
# undef EISCONN
59+
# undef ENOTCONN
60+
# undef ESHUTDOWN
61+
# undef ETOOMANYREFS
62+
# undef ETIMEDOUT
63+
# undef ECONNREFUSED
64+
# undef ELOOP
65+
# undef ENAMETOOLONG
66+
# undef EHOSTDOWN
67+
# undef EHOSTUNREACH
68+
# undef ENOTEMPTY
69+
# undef EPROCLIM
70+
# undef EUSERS
71+
# undef EDQUOT
72+
# undef ESTALE
73+
# undef EREMOTE
74+
75+
# undef EAGAIN
76+
#endif
77+
78+
/* section disabled in WinSock2.h */
79+
#define EWOULDBLOCK WSAEWOULDBLOCK
80+
#define EINPROGRESS WSAEINPROGRESS
81+
#define EALREADY WSAEALREADY
82+
#define ENOTSOCK WSAENOTSOCK
83+
#define EDESTADDRREQ WSAEDESTADDRREQ
84+
#define EMSGSIZE WSAEMSGSIZE
85+
#define EPROTOTYPE WSAEPROTOTYPE
86+
#define ENOPROTOOPT WSAENOPROTOOPT
87+
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
88+
#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
89+
#define EOPNOTSUPP WSAEOPNOTSUPP
90+
#define EPFNOSUPPORT WSAEPFNOSUPPORT
91+
#define EAFNOSUPPORT WSAEAFNOSUPPORT
92+
#define EADDRINUSE WSAEADDRINUSE
93+
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
94+
#define ENETDOWN WSAENETDOWN
95+
#define ENETUNREACH WSAENETUNREACH
96+
#define ENETRESET WSAENETRESET
97+
#define ECONNABORTED WSAECONNABORTED
98+
#define ECONNRESET WSAECONNRESET
99+
#define ENOBUFS WSAENOBUFS
100+
#define EISCONN WSAEISCONN
101+
#define ENOTCONN WSAENOTCONN
102+
#define ESHUTDOWN WSAESHUTDOWN
103+
#define ETOOMANYREFS WSAETOOMANYREFS
104+
#define ETIMEDOUT WSAETIMEDOUT
105+
#define ECONNREFUSED WSAECONNREFUSED
106+
#define ELOOP WSAELOOP
107+
#define ENAMETOOLONG WSAENAMETOOLONG
108+
#define EHOSTDOWN WSAEHOSTDOWN
109+
#define EHOSTUNREACH WSAEHOSTUNREACH
110+
#define ENOTEMPTY WSAENOTEMPTY
111+
#define EPROCLIM WSAEPROCLIM
112+
#define EUSERS WSAEUSERS
113+
#define EDQUOT WSAEDQUOT
114+
#define ESTALE WSAESTALE
115+
#define EREMOTE WSAEREMOTE
116+
117+
/* and an extra one */
118+
#define EAGAIN WSAEWOULDBLOCK
119+
120+
#endif

0 commit comments

Comments
 (0)