Skip to content

Instantly share code, notes, and snippets.

@weltling
Last active December 1, 2016 22:46
Show Gist options
  • Save weltling/f4371e67b47d3a948263b16e3c22560d to your computer and use it in GitHub Desktop.
Save weltling/f4371e67b47d3a948263b16e3c22560d to your computer and use it in GitHub Desktop.
--- a/xdebug_com.c
+++ b/xdebug_com.c
@@ -60,7 +60,7 @@ int xdebug_create_socket(const char *hostname, int dport TSRMLS_DC)
struct sockaddr_in6 sa;
socklen_t size = sizeof(sa);
#if WIN32|WINNT
- WSAPOLLFD ufds[1];
+ WSAPOLLFD ufds[1] = {0};
WORD wVersionRequested;
WSADATA wsaData;
char optval = 1;
@@ -109,7 +109,10 @@ int xdebug_create_socket(const char *hostname, int dport TSRMLS_DC)
/* Put socket in non-blocking mode so we can use poll for timeouts */
#ifdef WIN32
- ASSERT(-1 != ioctlsocket(sockfd, FIONBIO, (u_long*)&yes));
+ status = ioctlsocket(sockfd, FIONBIO, &yes);
+ if (SOCKET_ERROR == status) {
+ XDEBUG_LOG_PRINT(XG(remote_log_file), "W: Creating socket for '%s:%d', FIONBIO: %d.\n", hostname, dport, WSAGetLastError());
+ }
#else
fcntl(sockfd, F_SETFL, O_NONBLOCK);
#endif
@@ -143,10 +146,21 @@ int xdebug_create_socket(const char *hostname, int dport TSRMLS_DC)
}
ufds[0].fd = sockfd;
+#if WIN32|WINNT
+ ufds[0].events = POLLIN | POLLOUT;
+#else
ufds[0].events = POLLIN | POLLOUT | POLLPRI;
+#endif
while (1) {
sockerror = poll(ufds, 1, timeout);
-
+
+#if WIN32|WINNT
+ errno = WSAGetLastError();
+ if (errno == WSAEINPROGRESS || errno == WSAEWOULDBLOCK) {
+ /* XXX introduce retry count? */
+ continue;
+ }
+#endif
/* If an error occured when doing the poll */
if (sockerror == SOCK_ERR) {
#if WIN32|WINNT
@@ -221,7 +235,10 @@ int xdebug_create_socket(const char *hostname, int dport TSRMLS_DC)
/* If we got a socket, set the option "No delay" to true (1) */
if (sockfd > 0) {
#ifdef WIN32
- ioctlsocket(sockfd, FIONBIO, &no);
+ status = ioctlsocket(sockfd, FIONBIO, &no);
+ if (SOCKET_ERROR == status) {
+ XDEBUG_LOG_PRINT(XG(remote_log_file), "W: Creating socket for '%s:%d', FIONBIO: %d.\n", hostname, dport, WSAGetLastError());
+ }
#else
fcntl(sockfd, F_SETFL, 0);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment