Author: cgutman
Date: Sun Jun 27 20:05:52 2010
New Revision: 47866
URL:
http://svn.reactos.org/svn/reactos?rev=47866&view=rev
Log:
[DHCPCSVC]
- Use an event to signal when an adapter has been added
Modified:
trunk/reactos/dll/win32/dhcpcsvc/dhcp/adapter.c
trunk/reactos/dll/win32/dhcpcsvc/dhcp/dispatch.c
trunk/reactos/dll/win32/dhcpcsvc/include/rosdhcp.h
Modified: trunk/reactos/dll/win32/dhcpcsvc/dhcp/adapter.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/dhcpcsvc/dhcp/ad…
==============================================================================
--- trunk/reactos/dll/win32/dhcpcsvc/dhcp/adapter.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/dhcpcsvc/dhcp/adapter.c [iso-8859-1] Sun Jun 27 20:05:52 2010
@@ -227,10 +227,11 @@
/*
* XXX Figure out the way to bind a specific adapter to a socket.
*/
-DWORD WINAPI AdapterDiscoveryThread(LPVOID Unused) {
+DWORD WINAPI AdapterDiscoveryThread(LPVOID Context) {
PMIB_IFTABLE Table = (PMIB_IFTABLE) malloc(sizeof(MIB_IFTABLE));
DWORD Error, Size = sizeof(MIB_IFTABLE);
PDHCP_ADAPTER Adapter = NULL;
+ HANDLE AdapterStateChangedEvent = (HANDLE)Context;
struct interface_info *ifi = NULL;
int i;
@@ -345,6 +346,8 @@
ApiLock();
InsertTailList( &AdapterList, &Adapter->ListEntry );
+ DbgPrint("DHCPCSVC: Discovered new adapter [%s]\n",
Adapter->DhclientInfo.name);
+ SetEvent(AdapterStateChangedEvent);
ApiUnlock();
} else { free( Adapter ); Adapter = 0; }
} else { free( Adapter ); Adapter = 0; }
@@ -361,22 +364,27 @@
return Error;
}
-BOOLEAN StartAdapterDiscovery(VOID) {
- HANDLE ThreadHandle;
+HANDLE StartAdapterDiscovery(VOID) {
+ HANDLE ThreadHandle, EventHandle;
+
+ EventHandle = CreateEvent(NULL,
+ FALSE,
+ FALSE,
+ NULL);
ThreadHandle = CreateThread(NULL,
0,
AdapterDiscoveryThread,
- NULL,
+ (LPVOID)EventHandle,
0,
NULL);
if (ThreadHandle == NULL)
- return FALSE;
+ return NULL;
CloseHandle(ThreadHandle);
- return TRUE;
+ return EventHandle;
}
void AdapterStop() {
Modified: trunk/reactos/dll/win32/dhcpcsvc/dhcp/dispatch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/dhcpcsvc/dhcp/di…
==============================================================================
--- trunk/reactos/dll/win32/dhcpcsvc/dhcp/dispatch.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/dhcpcsvc/dhcp/dispatch.c [iso-8859-1] Sun Jun 27 20:05:52
2010
@@ -68,8 +68,10 @@
fd_set fds;
time_t howlong, cur_time;
struct timeval timeval;
-
- if (!StartAdapterDiscovery())
+ HANDLE AdapterStateChangedEvent;
+
+ AdapterStateChangedEvent = StartAdapterDiscovery();
+ if (!AdapterStateChangedEvent)
return;
ApiLock();
@@ -103,29 +105,31 @@
if (howlong > INT_MAX / 1000)
howlong = INT_MAX / 1000;
to_msec = howlong * 1000;
- } else
- to_msec = 5000;
-
- /* Set up the descriptors to be polled. */
- FD_ZERO(&fds);
-
- for (l = protocols; l; l = l->next)
- FD_SET(l->fd, &fds);
-
- /* Wait for a packet or a timeout... XXX */
- timeval.tv_sec = to_msec / 1000;
- timeval.tv_usec = to_msec % 1000;
-
- ApiUnlock();
-
- if (protocols)
+
+ /* Set up the descriptors to be polled. */
+ FD_ZERO(&fds);
+
+ for (l = protocols; l; l = l->next)
+ FD_SET(l->fd, &fds);
+
+ /* Wait for a packet or a timeout... XXX */
+ timeval.tv_sec = to_msec / 1000;
+ timeval.tv_usec = to_msec % 1000;
+
+ ApiUnlock();
+
count = select(0, &fds, NULL, NULL, &timeval);
- else {
- Sleep(to_msec);
- count = 0;
- }
-
- ApiLock();
+
+ ApiLock();
+ }
+ else
+ {
+ ApiUnlock();
+ WaitForSingleObject(AdapterStateChangedEvent, INFINITE);
+ ApiLock();
+
+ continue;
+ }
DH_DbgPrint(MID_TRACE,("Select: %d\n", count));
@@ -148,6 +152,8 @@
}
}
} while (1);
+
+ CloseHandle(AdapterStateChangedEvent);
ApiUnlock();
}
Modified: trunk/reactos/dll/win32/dhcpcsvc/include/rosdhcp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/dhcpcsvc/include…
==============================================================================
--- trunk/reactos/dll/win32/dhcpcsvc/include/rosdhcp.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/dhcpcsvc/include/rosdhcp.h [iso-8859-1] Sun Jun 27 20:05:52
2010
@@ -77,7 +77,7 @@
#define srandom srand
void AdapterInit(VOID);
-BOOLEAN StartAdapterDiscovery(VOID);
+HANDLE StartAdapterDiscovery(VOID);
void AdapterStop(VOID);
extern PDHCP_ADAPTER AdapterGetFirst();
extern PDHCP_ADAPTER AdapterGetNext(PDHCP_ADAPTER);