2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afs/param.h>
18 #include "TaAfsAdmSvrClientInternal.h"
19 #include <WINNT/AfsAppLib.h>
23 * VARIABLES __________________________________________________________________
33 HANDLE hCallbackThread;
39 * PROTOTYPES _________________________________________________________________
43 DWORD WINAPI ClientPingThread (LPVOID lp);
45 DWORD WINAPI ClientCallbackThread (LPVOID lp);
49 * ROUTINES ___________________________________________________________________
53 void StartPingThread (UINT_PTR idClient)
58 for (ii = 0; ii < l.cdwClients; ++ii)
60 if (!l.adwClients[ ii ])
63 if (REALLOC (l.adwClients, l.cdwClients, 1+ii, 1))
65 l.adwClients[ ii ] = idClient;
71 l.hPingThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)ClientPingThread, (LPVOID)0, 0, &dwThreadID);
78 void StopPingThread (UINT_PTR idClient)
82 for (size_t ii = 0; ii < l.cdwClients; ++ii)
84 if (l.adwClients[ ii ] == idClient)
85 l.adwClients[ ii ] = 0;
92 DWORD WINAPI ClientPingThread (LPVOID lp)
96 Sleep (csecAFSADMSVR_CLIENT_PING * 1000L); // server adds race allowance
100 for (size_t ii = 0; ii < l.cdwClients; ++ii)
103 if ((idClient = l.adwClients[ ii ]) == 0)
111 if (!AfsAdmSvr_Ping (idClient, &status))
113 if (status == ERROR_INVALID_HANDLE) // we've been disconnected!
114 StopPingThread (idClient);
127 l.hPingThread = NULL;
132 void StartCallbackThread (void)
135 if ((++l.cReqCallback) == 1)
138 l.hCallbackThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)ClientCallbackThread, (LPVOID)0, 0, &dwThreadID);
144 void StopCallbackThread (void)
147 if (!(l.cReqCallback) || !(--l.cReqCallback))
149 if (l.hCallbackThread)
151 TerminateThread (l.hCallbackThread, 0);
152 l.hCallbackThread = NULL;
159 DWORD WINAPI ClientCallbackThread (LPVOID lp)
161 // The callback thread's task is simple: it initiates a particular
162 // RPC, which never returns. (Well, actually, it will return if the
163 // server shuts down.) By leaving a thread active, the server has a
164 // context in which to perform callback calls.
168 AfsAdmSvr_CallbackHost();
174 l.hCallbackThread = NULL;