[DHCPCSVC] Add the ability to stop the DHCP client

- Use a stop event to terminate the dispatch loop.
- Report to the services manager that the service can be stopped or shut-down while it is running.

CORE-14390
This commit is contained in:
Eric Kohl 2018-03-21 21:07:26 +01:00
parent 8b84b1c6b3
commit 9febc82acf
3 changed files with 51 additions and 43 deletions

View file

@ -63,21 +63,23 @@ void (*bootp_packet_handler)(struct interface_info *,
* bootp_packet_handler hook to try to do something with it.
*/
void
dispatch(void)
dispatch(HANDLE hStopEvent)
{
int count, to_msec;
struct protocol *l;
time_t howlong, cur_time;
HANDLE Events[2];
int EventCount = 1;
HANDLE Events[3];
int EventCount = 2;
Events[0] = StartAdapterDiscovery();
if (!Events[0])
return;
AdapterStateChangedEvent = Events[0];
Events[1] = WSA_INVALID_EVENT;
Events[1] = hStopEvent;
Events[2] = WSA_INVALID_EVENT;
ApiLock();
do {
@ -116,29 +118,29 @@ dispatch(void)
to_msec = INFINITE;
}
if (Events[1] == WSA_INVALID_EVENT && DhcpSocket != INVALID_SOCKET)
if (Events[2] == WSA_INVALID_EVENT && DhcpSocket != INVALID_SOCKET)
{
Events[1] = WSACreateEvent();
if (Events[1] != WSA_INVALID_EVENT)
Events[2] = WSACreateEvent();
if (Events[2] != WSA_INVALID_EVENT)
{
count = WSAEventSelect(DhcpSocket, Events[1], FD_READ | FD_CLOSE);
count = WSAEventSelect(DhcpSocket, Events[2], FD_READ | FD_CLOSE);
if (count != NO_ERROR)
{
WSACloseEvent(Events[1]);
Events[1] = WSA_INVALID_EVENT;
WSACloseEvent(Events[2]);
Events[2] = WSA_INVALID_EVENT;
}
else
{
EventCount = 2;
EventCount = 3;
}
}
}
else if (Events[1] != WSA_INVALID_EVENT && DhcpSocket == INVALID_SOCKET)
else if (Events[2] != WSA_INVALID_EVENT && DhcpSocket == INVALID_SOCKET)
{
WSACloseEvent(Events[1]);
Events[1] = WSA_INVALID_EVENT;
WSACloseEvent(Events[2]);
Events[2] = WSA_INVALID_EVENT;
EventCount = 1;
EventCount = 2;
}
ApiUnlock();
@ -153,11 +155,16 @@ dispatch(void)
continue;
}
else if (count == WAIT_OBJECT_0 + 1)
{
/* Stop event signalled */
break;
}
else if (count == WAIT_OBJECT_0 + 2)
{
/* Packet received */
/* WSA events are manual reset events */
WSAResetEvent(Events[1]);
WSAResetEvent(Events[2]);
}
else
{
@ -178,7 +185,8 @@ dispatch(void)
AdapterStateChangedEvent = NULL;
CloseHandle(Events[0]);
WSACloseEvent(Events[1]);
CloseHandle(Events[1]);
WSACloseEvent(Events[2]);
ApiUnlock();
}