[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b

aCaB acab at clamav.net
Sun Apr 4 01:17:52 UTC 2010


The following commit has been merged in the debian/unstable branch:
commit 1c4d9a22faea56a1c2e75af1d0b6f008dbc325d4
Author: aCaB <acab at clamav.net>
Date:   Fri Jan 29 14:44:55 2010 +0100

    clamd-win32: WIP#2

diff --git a/clamd/others.c b/clamd/others.c
index f0d8387..b3271b1 100644
--- a/clamd/others.c
+++ b/clamd/others.c
@@ -59,7 +59,6 @@
 #if HAVE_POLL_H
 #include <poll.h>
 #else /* HAVE_POLL_H */
-#undef HAVE_POLL
 #if HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif /* HAVE_SYS_SELECT_H */
diff --git a/clamd/server-th.c b/clamd/server-th.c
index 7a131ea..6e92e4f 100644
--- a/clamd/server-th.c
+++ b/clamd/server-th.c
@@ -298,11 +298,20 @@ struct acceptdata {
     pthread_cond_t cond_nfds;
     int max_queue;
     int commandtimeout;
+#ifdef _WIN32
+    HANDLE event_wake_recv;
+    HANDLE event_wake_accept;
+#else
     int syncpipe_wake_recv[2];
     int syncpipe_wake_accept[2];
+#endif
 };
 
+#ifdef _WIN32
+#define ACCEPTDATA_INIT(mutex1, mutex2) { FDS_INIT(mutex1), FDS_INIT(mutex2), PTHREAD_COND_INITIALIZER, 0, 0, NULL, NULL}
+#else
 #define ACCEPTDATA_INIT(mutex1, mutex2) { FDS_INIT(mutex1), FDS_INIT(mutex2), PTHREAD_COND_INITIALIZER, 0, 0, {-1, -1}, {-1, -1}}
+#endif
 
 static void *acceptloop_th(void *arg)
 {
@@ -339,6 +348,7 @@ static void *acceptloop_th(void *arg)
 	    struct fd_buf *buf = &fds->buf[i];
 	    if (!buf->got_newdata)
 		continue;
+#ifndef _WIN32 // FIXME
 	    if (buf->fd == data->syncpipe_wake_accept[0]) {
 		/* dummy sync pipe, just to wake us */
 		if (read(buf->fd, buff, sizeof(buff)) < 0) {
@@ -346,6 +356,7 @@ static void *acceptloop_th(void *arg)
 		}
 		continue;
 	    }
+#endif
 	    if (buf->got_newdata == -1) {
 		logg("$Acceptloop closed FD: %d\n", buf->fd);
 		shutdown(buf->fd, 2);
@@ -406,10 +417,14 @@ static void *acceptloop_th(void *arg)
 		}
 
 		/* notify recvloop */
+#ifdef _WIN32
+		SetEvent(data->event_wake_recv);
+#else
 		if (write(data->syncpipe_wake_recv[1], "", 1) == -1) {
 		    logg("!write syncpipe failed\n");
 		    continue;
 		}
+#endif
 	    } else if (errno != EINTR) {
 		/* very bad - need to exit or restart */
 #ifdef HAVE_STRERROR_R
@@ -446,10 +461,13 @@ static void *acceptloop_th(void *arg)
     pthread_mutex_lock(&exit_mutex);
     progexit = 1;
     pthread_mutex_unlock(&exit_mutex);
+#ifdef _WIN32
+    SetEvent(data->event_wake_recv);
+#else
     if (write(data->syncpipe_wake_recv[1], "", 1) < 0) {
 	logg("$Syncpipe write failed\n");
     }
-
+#endif
     return NULL;
 }
 
@@ -1046,14 +1064,16 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
 	    cl_engine_free(engine);
 	    return 1;
 	}
-
+#ifdef _WIN32
+	acceptdata.event_wake_accept = CreateEvent(NULL, TRUE, FALSE, NULL);
+	acceptdata.event_wake_recv = CreateEvent(NULL, TRUE, FALSE, NULL);
+#else
     if (pipe(acceptdata.syncpipe_wake_recv) == -1 ||
 	(pipe(acceptdata.syncpipe_wake_accept) == -1)) {
 
 	logg("!pipe failed\n");
 	exit(-1);
     }
-
     syncpipe_wake_recv_w = acceptdata.syncpipe_wake_recv[1];
 
     if (fds_add(fds, acceptdata.syncpipe_wake_recv[0], 1, 0) == -1 ||
@@ -1061,6 +1081,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
 	logg("!failed to add pipe fd\n");
 	exit(-1);
     }
+#endif
 
     if ((thr_pool = thrmgr_new(max_threads, idletimeout, max_queue, scanner_thread)) == NULL) {
 	logg("!thrmgr_new failed\n");
@@ -1109,6 +1130,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
 	    if (!buf->got_newdata)
 		continue;
 
+#ifndef _WIN32 //FIXME
 	    if (buf->fd == acceptdata.syncpipe_wake_recv[0]) {
 		/* dummy sync pipe, just to wake us */
 		if (read(buf->fd, buff, sizeof(buff)) < 0) {
@@ -1116,7 +1138,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
 		}
 		continue;
 	    }
-
+#endif
 	    if (buf->got_newdata == -1) {
 		if (buf->mode == MODE_WAITREPLY) {
 		    logg("$mode WAIT_REPLY -> closed\n");
@@ -1288,9 +1310,13 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
     pthread_mutex_lock(&exit_mutex);
     progexit = 1;
     pthread_mutex_unlock(&exit_mutex);
+#ifdef _WIN32
+    SetEvent(acceptdata.event_wake_accept);
+#else
     if (write(acceptdata.syncpipe_wake_accept[1], "", 1) < 0) {
 	logg("^Write to syncpipe failed\n");
     }
+#endif
     /* Destroy the thread manager.
      * This waits for all current tasks to end
      */
@@ -1310,8 +1336,13 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
 
     pthread_join(accept_th, NULL);
     fds_free(fds);
+#ifdef _WIN32
+    CloseHandle(acceptdata.event_wake_accept);
+    CloseHandle(acceptdata.event_wake_recv);
+#else
     close(acceptdata.syncpipe_wake_accept[1]);
     close(acceptdata.syncpipe_wake_recv[1]);
+#endif
     if(dbstat.entries)
 	cl_statfree(&dbstat);
     logg("*Shutting down the main socket%s.\n", (nsockets > 1) ? "s" : "");
diff --git a/win32/clamav-config.h b/win32/clamav-config.h
index 6751441..cbbeccd 100644
--- a/win32/clamav-config.h
+++ b/win32/clamav-config.h
@@ -269,7 +269,7 @@
 #define HAVE_OPENDIR 1
 
 /* Define to 1 if you have the `poll' function. */
-/* #undef HAVE_POLL */
+#define HAVE_POLL 1
 
 /* Define to 1 if you have the <poll.h> header file. */
 /* #undef HAVE_POLL_H */
diff --git a/win32/clamd.vcproj b/win32/clamd.vcproj
index f42c21f..c246e84 100644
--- a/win32/clamd.vcproj
+++ b/win32/clamd.vcproj
@@ -1,251 +1,251 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
-	Keyword="Win32Proj"
-	Name="clamd"
-	ProjectGUID="{B3CA73CF-E71E-42F3-95DE-43797A86C798}"
-	ProjectType="Visual C++"
-	RootNamespace="clamd"
-	TargetFrameworkVersion="196613"
-	Version="9,00"
-	>
-	<Platforms>
-		<Platform
-			Name="Win32"
-		/>
-	</Platforms>
-	<ToolFiles>
-	</ToolFiles>
-	<Configurations>
-		<Configuration
-			CharacterSet="2"
-			ConfigurationType="1"
-			IntermediateDirectory="$(SolutionDir)build\$(ProjectName)\$(ConfigurationName)"
-			Name="Debug|Win32"
-			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-			>
-			<Tool
-				Name="VCPreBuildEventTool"
-			/>
-			<Tool
-				Name="VCCustomBuildTool"
-			/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"
-			/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"
-			/>
-			<Tool
-				Name="VCMIDLTool"
-			/>
-			<Tool
-				AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)compat&quot;;&quot;$(SolutionDir)3rdparty\zlib&quot;;&quot;$(SolutionDir)3rdparty\pthreads&quot;;&quot;$(SolutionDir)3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
-				BasicRuntimeChecks="3"
-				CompileAs="1"
-				DebugInformationFormat="3"
-				DisableSpecificWarnings="4996;4244"
-				MinimalRebuild="true"
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				PreprocessorDefinitions="WIN32_LEAN_AND_MEAN;HAVE_CONFIG_H;_BIND_TO_CURRENT_VCLIBS_VERSION=1"
-				RuntimeLibrary="3"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-			/>
-			<Tool
-				Name="VCManagedResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCPreLinkEventTool"
-			/>
-			<Tool
-				GenerateDebugInformation="true"
-				LinkIncremental="1"
-				Name="VCLinkerTool"
-				SubSystem="1"
-				TargetMachine="1"
-			/>
-			<Tool
-				Name="VCALinkTool"
-			/>
-			<Tool
-				Name="VCManifestTool"
-			/>
-			<Tool
-				Name="VCXDCMakeTool"
-			/>
-			<Tool
-				Name="VCBscMakeTool"
-			/>
-			<Tool
-				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
-			<Tool
-				Name="VCPostBuildEventTool"
-			/>
-		</Configuration>
-		<Configuration
-			CharacterSet="2"
-			ConfigurationType="1"
-			IntermediateDirectory="$(SolutionDir)build\$(ProjectName)\$(ConfigurationName)"
-			Name="Release|Win32"
-			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-			WholeProgramOptimization="1"
-			>
-			<Tool
-				Name="VCPreBuildEventTool"
-			/>
-			<Tool
-				Name="VCCustomBuildTool"
-			/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"
-			/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"
-			/>
-			<Tool
-				Name="VCMIDLTool"
-			/>
-			<Tool
-				AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)compat&quot;;&quot;$(SolutionDir)3rdparty\zlib&quot;;&quot;$(SolutionDir)3rdparty\pthreads&quot;;&quot;$(SolutionDir)3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
-				CompileAs="1"
-				DebugInformationFormat="3"
-				DisableSpecificWarnings="4996;4244"
-				EnableFunctionLevelLinking="true"
-				EnableIntrinsicFunctions="true"
-				Name="VCCLCompilerTool"
-				Optimization="2"
-				PreprocessorDefinitions="WIN32_LEAN_AND_MEAN;HAVE_CONFIG_H;_BIND_TO_CURRENT_VCLIBS_VERSION=1"
-				RuntimeLibrary="2"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-			/>
-			<Tool
-				Name="VCManagedResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCResourceCompilerTool"
-			/>
-			<Tool
-				Name="VCPreLinkEventTool"
-			/>
-			<Tool
-				EnableCOMDATFolding="2"
-				GenerateDebugInformation="true"
-				LinkIncremental="1"
-				Name="VCLinkerTool"
-				OptimizeReferences="2"
-				SubSystem="1"
-				TargetMachine="1"
-			/>
-			<Tool
-				Name="VCALinkTool"
-			/>
-			<Tool
-				Name="VCManifestTool"
-			/>
-			<Tool
-				Name="VCXDCMakeTool"
-			/>
-			<Tool
-				Name="VCBscMakeTool"
-			/>
-			<Tool
-				Name="VCFxCopTool"
-			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
-			<Tool
-				Name="VCPostBuildEventTool"
-			/>
-		</Configuration>
-	</Configurations>
-	<References>
-	</References>
-	<Files>
-		<Filter
-			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
-			Name="Source Files"
-			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
-			>
-			<File
-				RelativePath="..\clamd\clamd.c"
-				>
-			</File>
-			<File
-				RelativePath="..\clamd\localserver.c"
-				>
-			</File>
-			<File
-				RelativePath="..\clamd\others.c"
-				>
-			</File>
-			<File
-				RelativePath="..\clamd\scanner.c"
-				>
-			</File>
-			<File
-				RelativePath="..\clamd\server-th.c"
-				>
-			</File>
-			<File
-				RelativePath="..\clamd\session.c"
-				>
-			</File>
-			<File
-				RelativePath="..\clamd\tcpserver.c"
-				>
-			</File>
-			<File
-				RelativePath="..\clamd\thrmgr.c"
-				>
-			</File>
-			<Filter
-				Name="shared"
-				>
-				<File
-					RelativePath="..\shared\misc.c"
-					>
-				</File>
-				<File
-					RelativePath="..\shared\output.c"
-					>
-				</File>
-			</Filter>
-			<Filter
-				Name="compat"
-				>
-				<File
-					RelativePath=".\compat\libgen.c"
-					>
-				</File>
-				<File
-					RelativePath=".\compat\setargv.c"
-					>
-				</File>
-			</Filter>
-		</Filter>
-		<Filter
-			Filter="h;hpp;hxx;hm;inl;inc;xsd"
-			Name="Header Files"
-			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
-			>
-		</Filter>
-		<Filter
-			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
-			Name="Resource Files"
-			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
-			>
-		</Filter>
-	</Files>
-	<Globals>
-	</Globals>
-</VisualStudioProject>
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9,00"
+	Name="clamd"
+	ProjectGUID="{B3CA73CF-E71E-42F3-95DE-43797A86C798}"
+	RootNamespace="clamd"
+	Keyword="Win32Proj"
+	TargetFrameworkVersion="196613"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(SolutionDir)build\$(ProjectName)\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)compat&quot;;&quot;$(SolutionDir)3rdparty\zlib&quot;;&quot;$(SolutionDir)3rdparty\pthreads&quot;;&quot;$(SolutionDir)3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
+				PreprocessorDefinitions="WIN32_LEAN_AND_MEAN;HAVE_CONFIG_H;_BIND_TO_CURRENT_VCLIBS_VERSION=1"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+				CompileAs="1"
+				DisableSpecificWarnings="4996;4244;4090;4018"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="1"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(SolutionDir)build\$(ProjectName)\$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="2"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				EnableIntrinsicFunctions="true"
+				AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)compat&quot;;&quot;$(SolutionDir)3rdparty\zlib&quot;;&quot;$(SolutionDir)3rdparty\pthreads&quot;;&quot;$(SolutionDir)3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
+				PreprocessorDefinitions="WIN32_LEAN_AND_MEAN;HAVE_CONFIG_H;_BIND_TO_CURRENT_VCLIBS_VERSION=1"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+				CompileAs="1"
+				DisableSpecificWarnings="4996;4244;4090;4018"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				LinkIncremental="1"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath="..\clamd\clamd.c"
+				>
+			</File>
+			<File
+				RelativePath="..\clamd\localserver.c"
+				>
+			</File>
+			<File
+				RelativePath="..\clamd\others.c"
+				>
+			</File>
+			<File
+				RelativePath="..\clamd\scanner.c"
+				>
+			</File>
+			<File
+				RelativePath="..\clamd\server-th.c"
+				>
+			</File>
+			<File
+				RelativePath="..\clamd\session.c"
+				>
+			</File>
+			<File
+				RelativePath="..\clamd\tcpserver.c"
+				>
+			</File>
+			<File
+				RelativePath="..\clamd\thrmgr.c"
+				>
+			</File>
+			<Filter
+				Name="shared"
+				>
+				<File
+					RelativePath="..\shared\misc.c"
+					>
+				</File>
+				<File
+					RelativePath="..\shared\output.c"
+					>
+				</File>
+			</Filter>
+			<Filter
+				Name="compat"
+				>
+				<File
+					RelativePath=".\compat\libgen.c"
+					>
+				</File>
+				<File
+					RelativePath=".\compat\setargv.c"
+					>
+				</File>
+			</Filter>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+			>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
diff --git a/win32/compat/net.c b/win32/compat/net.c
index d46cac9..3113752 100644
--- a/win32/compat/net.c
+++ b/win32/compat/net.c
@@ -24,6 +24,7 @@
 #ifdef W2K_DNSAAPI_COMPAT
 #include <Wspiapi.h>
 #endif
+#include <stdlib.h>
 #include "net.h"
 #include "w32_errno.h"
 
@@ -348,3 +349,57 @@ int w32_shutdown(int sockfd, int how) {
     }
     return 0;
 }
+
+
+struct w32polldata {
+    HANDLE setme;
+    HANDLE event;
+    HANDLE waiter;
+    struct pollfd *polldata;
+};
+
+VOID CALLBACK poll_cb(PVOID param, BOOLEAN timedout) {
+    WSANETWORKEVENTS evt;
+    struct w32polldata *item = (struct w32polldata *)param;
+    if(!timedout) {
+	unsigned int i;
+	WSAEnumNetworkEvents(item->polldata->fd, item->event, &evt);
+	for(i=0; i<evt.lNetworkEvents; i++) {
+	    if(evt.iErrorCode[i] & (FD_ACCEPT|FD_READ)) item->polldata->revents |= POLLIN;
+	    if(evt.iErrorCode[i] & FD_CLOSE) item->polldata->revents |= POLLHUP;
+	}
+    }
+}
+
+int w32_poll(struct pollfd *fds, int nfds, int timeout) {
+    HANDLE setme = CreateEvent(NULL, TRUE, FALSE, NULL);
+    struct w32polldata *items;
+    unsigned int i, ret = 0;
+
+    timeout = timeout>=0 ? timeout*1000 : INFINITE;
+    if(!nfds) {
+	Sleep(timeout);
+	return 0;
+    }
+    items = malloc(nfds * sizeof(struct w32polldata));
+    for(i=0; i<nfds; i++) {
+	items[i].event = CreateEvent(NULL, TRUE, FALSE, NULL);
+	items[i].polldata = &fds[i];
+	items[i].setme = setme;
+	if(WSAEventSelect(fds[i].fd, items[i].event, FD_ACCEPT|FD_READ|FD_CLOSE)) {
+	    /* handle error here */
+	}
+	if(RegisterWaitForSingleObject(&items[i].waiter, items[i].event, poll_cb, &items[i], timeout, WT_EXECUTEONLYONCE)) {
+	    /* handle errors here */
+	}
+    }
+    WaitForSingleObject(setme, timeout); /* FIXME - add the pipe here */
+    for(i=0; i<nfds; i++) {
+	UnregisterWait(items[i].waiter);
+	WSAEventSelect(fds[i].fd, items[i].event, 0);
+	CloseHandle(items[i].event);
+	ret += (items[i].polldata->revents != 0);
+    }
+    free(items);
+    return ret;
+}
diff --git a/win32/compat/net.h b/win32/compat/net.h
index 8f4ec7f..6b765e1 100644
--- a/win32/compat/net.h
+++ b/win32/compat/net.h
@@ -39,6 +39,7 @@ void w32_freeaddrinfo(struct addrinfo *res);
 const char *w32_inet_ntop(int af, const void *src, char *dst, socklen_t size);
 struct hostent *w32_gethostbyname(const char *name);
 int w32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
+int w32_poll(struct pollfd *fds, int nfds, int timeout);
 int w32_accept(int sockfd, const struct sockaddr *addr, socklen_t *addrlen);
 int w32_listen(int sockfd, int backlog);
 int w32_shutdown(int sockfd, int how);
diff --git a/win32/libclamav.def b/win32/libclamav.def
index 5ad4c67..a80f97f 100644
--- a/win32/libclamav.def
+++ b/win32/libclamav.def
@@ -142,6 +142,7 @@ EXPORTS w32_freeaddrinfo
 EXPORTS w32_inet_ntop
 EXPORTS w32_gethostbyname
 EXPORTS w32_select
+EXPORTS w32_poll
 EXPORTS w32_stat
 EXPORTS w32_strerror
 EXPORTS w32_strerror_r
diff --git a/win32/platform.h b/win32/platform.h
index e1e42b2..22fc726 100644
--- a/win32/platform.h
+++ b/win32/platform.h
@@ -46,6 +46,7 @@ char *strptime(const char *s, const char *format, struct tm *tm);
 #define inet_ntop w32_inet_ntop
 #define gethostbyname w32_gethostbyname
 #define select w32_select
+#define poll w32_poll
 #define strerror w32_strerror
 #define strerror_r w32_strerror_r
 #define ftruncate _chsize
diff --git a/win32/update-win32.pl b/win32/update-win32.pl
index 74184fd..af03e96 100755
--- a/win32/update-win32.pl
+++ b/win32/update-win32.pl
@@ -104,7 +104,7 @@ my %CONF = (
     'HAVE_MMAP' => -1,
     'HAVE_NDIR_H' => -1,
     'HAVE_OPENDIR' => '1',
-    'HAVE_POLL' => -1,
+    'HAVE_POLL' => '1',
     'HAVE_POLL_H' => -1,
     'HAVE_PRAGMA_PACK' => '1',
     'HAVE_PRAGMA_PACK_HPPA' => -1,

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list