[DHCPCSVC]
authorCameron Gutman <aicommander@gmail.com>
Sun, 27 Jun 2010 20:05:52 +0000 (20:05 +0000)
committerCameron Gutman <aicommander@gmail.com>
Sun, 27 Jun 2010 20:05:52 +0000 (20:05 +0000)
- Use an event to signal when an adapter has been added

svn path=/trunk/; revision=47866

reactos/dll/win32/dhcpcsvc/dhcp/adapter.c
reactos/dll/win32/dhcpcsvc/dhcp/dispatch.c
reactos/dll/win32/dhcpcsvc/include/rosdhcp.h

index 3248478..73a45e0 100644 (file)
@@ -227,10 +227,11 @@ InterfaceConnected(MIB_IFROW IfEntry)
 /*
  * XXX Figure out the way to bind a specific adapter to a socket.
  */
 /*
  * 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;
     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;
 
     struct interface_info *ifi = NULL;
     int i;
 
@@ -345,6 +346,8 @@ DWORD WINAPI AdapterDiscoveryThread(LPVOID Unused) {
 
                     ApiLock();
                     InsertTailList( &AdapterList, &Adapter->ListEntry );
 
                     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; }
                     ApiUnlock();
                 } else { free( Adapter ); Adapter = 0; }
             } else { free( Adapter ); Adapter = 0; }
@@ -361,22 +364,27 @@ DWORD WINAPI AdapterDiscoveryThread(LPVOID Unused) {
     return Error;
 }
 
     return Error;
 }
 
-BOOLEAN StartAdapterDiscovery(VOID) {
-    HANDLE ThreadHandle;
+HANDLE StartAdapterDiscovery(VOID) {
+    HANDLE ThreadHandle, EventHandle;
+
+    EventHandle = CreateEvent(NULL,
+                              FALSE,
+                              FALSE,
+                              NULL);
 
     ThreadHandle = CreateThread(NULL,
                                 0,
                                 AdapterDiscoveryThread,
 
     ThreadHandle = CreateThread(NULL,
                                 0,
                                 AdapterDiscoveryThread,
-                                NULL,
+                                (LPVOID)EventHandle,
                                 0,
                                 NULL);
 
     if (ThreadHandle == NULL)
                                 0,
                                 NULL);
 
     if (ThreadHandle == NULL)
-        return FALSE;
+        return NULL;
 
     CloseHandle(ThreadHandle);
 
 
     CloseHandle(ThreadHandle);
 
-    return TRUE;
+    return EventHandle;
 }
 
 void AdapterStop() {
 }
 
 void AdapterStop() {
index 8749a12..a0ce1d0 100644 (file)
@@ -68,8 +68,10 @@ dispatch(void)
     fd_set fds;
     time_t howlong, cur_time;
     struct timeval timeval;
     fd_set fds;
     time_t howlong, cur_time;
     struct timeval timeval;
+    HANDLE AdapterStateChangedEvent;
 
 
-    if (!StartAdapterDiscovery())
+    AdapterStateChangedEvent = StartAdapterDiscovery();
+    if (!AdapterStateChangedEvent)
          return;
 
     ApiLock();
          return;
 
     ApiLock();
@@ -103,29 +105,31 @@ dispatch(void)
             if (howlong > INT_MAX / 1000)
                 howlong = INT_MAX / 1000;
             to_msec = howlong * 1000;
             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);
+            /* Set up the descriptors to be polled. */
+            FD_ZERO(&fds);
 
 
-        for (l = protocols; l; l = l->next)
-             FD_SET(l->fd, &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;
+            /* Wait for a packet or a timeout... XXX */
+            timeval.tv_sec = to_msec / 1000;
+            timeval.tv_usec = to_msec % 1000;
 
 
-        ApiUnlock();
+            ApiUnlock();
 
 
-        if (protocols)
             count = select(0, &fds, NULL, NULL, &timeval);
             count = select(0, &fds, NULL, NULL, &timeval);
-        else {
-            Sleep(to_msec);
-            count = 0;
+
+            ApiLock();
         }
         }
+        else
+        {
+            ApiUnlock();
+            WaitForSingleObject(AdapterStateChangedEvent, INFINITE);
+            ApiLock();
 
 
-        ApiLock();
+            continue;
+        }
 
         DH_DbgPrint(MID_TRACE,("Select: %d\n", count));
 
 
         DH_DbgPrint(MID_TRACE,("Select: %d\n", count));
 
@@ -149,6 +153,8 @@ dispatch(void)
         }
     } while (1);
 
         }
     } while (1);
 
+    CloseHandle(AdapterStateChangedEvent);
+
     ApiUnlock();
 }
 
     ApiUnlock();
 }
 
index 019ab12..8f84186 100644 (file)
@@ -77,7 +77,7 @@ typedef DWORD (*PipeSendFunc)( COMM_DHCP_REPLY *Reply );
 #define srandom srand
 
 void AdapterInit(VOID);
 #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);
 void AdapterStop(VOID);
 extern PDHCP_ADAPTER AdapterGetFirst();
 extern PDHCP_ADAPTER AdapterGetNext(PDHCP_ADAPTER);