ws2_32: WSACleanup cleans up open sockets (OSX only)
Matt Durgavich
mattdurgavich at gmail.com
Fri Jul 31 22:19:28 CDT 2015
>From 991ce8e253fe794dcf77c31dc1eca75c6c654289 Mon Sep 17 00:00:00 2001
From: Matt Durgavich <mattdurgavich at gmail.com>
Date: Fri, 31 Jul 2015 23:05:49 -0400
Subject: ws2_32: WSACleanup cleans up open sockets (OSX only)
---
configure.ac | 2 +-
dlls/ws2_32/socket.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 45b8fdb..9b2fe14 100644
--- a/configure.ac
+++ b/configure.ac
@@ -867,7 +867,7 @@ uninstall::
libwine_targets="libwine.dylib libwine.$libwine_soversion.dylib
libwine.$libwine_version.dylib"
AC_SUBST(LIBWINE_RULES,["
OBJS = \$(C_SRCS:.c=.o) \$(EXTRA_OBJS)
-
+ AC_CHECK_HEADER(libproc.h, AC_DEFINE(HAVE_LIBPROC_H))
all: libwine.dylib
libwine.$libwine_version.dylib: \$(OBJS)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index b06d7e7..f9cef96 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -132,6 +132,14 @@
# include <sys/time.h>
#endif
+#ifdef HAVE_LIBPROC_H
+# include <libproc.h>
+#endif
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "ntstatus.h"
@@ -1449,6 +1457,30 @@ int WINAPI WSAStartup(WORD wVersionRequested,
LPWSADATA lpWSAData)
return 0;
}
+static void close_open_sockets() {
+#ifdef HAVE_LIBPROC_H
+ int pid = getpid();
+ int bufferSizeNeeded = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
+ if (bufferSizeNeeded > 0) {
+ struct proc_fdinfo *infos = (struct
proc_fdinfo*)malloc(bufferSizeNeeded);
+ int ret = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, infos,
bufferSizeNeeded);
+ int numfds = bufferSizeNeeded / PROC_PIDLISTFD_SIZE;
+ if (ret >= 0) {
+ for (int i = 0; i < numfds; ++i ) {
+ int32_t fd = infos[i].proc_fd;
+ uint32_t type = infos[i].proc_fdtype;
+ if (type == PROX_FDTYPE_SOCKET) {
+ TRACE("Closing socket with descriptor %d\n", fd);
+ close(fd);
+ }
+ }
+ }
+ free(infos);
+ }
+#else
+ FIXME("stub")
+#endif
+}
/***********************************************************************
* WSACleanup (WS2_32.116)
@@ -1458,8 +1490,14 @@ INT WINAPI WSACleanup(void)
if (num_startup) {
num_startup--;
TRACE("pending cleanups: %d\n", num_startup);
+ if (num_startup == 0) {
+ TRACE("cleaning up open sockets");
+ close_open_sockets();
+ }
return 0;
}
+
+ /* Close all sockets */
SetLastError(WSANOTINITIALISED);
return SOCKET_ERROR;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20150731/45d793e8/attachment-0001.html>
More information about the wine-patches
mailing list