os/xdmcp: Replace xdmcp block/wakeup handlers with timer and NotifyFd
This removes the block and wakeup handlers and replaces them with a combination of a NotifyFd callback and timers. Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
6a121f5538
commit
49c0f2413d
114
os/xdmcp.c
114
os/xdmcp.c
|
@ -82,10 +82,10 @@ static struct sockaddr_in req_sockaddr;
|
||||||
#endif
|
#endif
|
||||||
static int req_socklen;
|
static int req_socklen;
|
||||||
static CARD32 SessionID;
|
static CARD32 SessionID;
|
||||||
static CARD32 timeOutTime;
|
|
||||||
static int timeOutRtx;
|
static int timeOutRtx;
|
||||||
static CARD16 DisplayNumber;
|
static CARD16 DisplayNumber;
|
||||||
static xdmcp_states XDM_INIT_STATE = XDM_OFF;
|
static xdmcp_states XDM_INIT_STATE = XDM_OFF;
|
||||||
|
static OsTimerPtr xdmcp_timer;
|
||||||
|
|
||||||
#ifdef HASXDMAUTH
|
#ifdef HASXDMAUTH
|
||||||
static char *xdmAuthCookie;
|
static char *xdmAuthCookie;
|
||||||
|
@ -197,13 +197,9 @@ static void send_packet(void);
|
||||||
|
|
||||||
static void timeout(void);
|
static void timeout(void);
|
||||||
|
|
||||||
static void XdmcpBlockHandler(void *data ,
|
static void XdmcpSocketNotify(int fd, int ready, void *data);
|
||||||
struct timeval **wt,
|
|
||||||
void *LastSelectMask);
|
|
||||||
|
|
||||||
static void XdmcpWakeupHandler(void *data,
|
static CARD32 XdmcpTimerNotify(OsTimerPtr timer, CARD32 time, void *arg);
|
||||||
int i,
|
|
||||||
void *LastSelectMask);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register the Manufacturer display ID
|
* Register the Manufacturer display ID
|
||||||
|
@ -579,6 +575,21 @@ XdmcpRegisterDisplayClass(const char *name, int length)
|
||||||
DisplayClass.data[i] = (CARD8) name[i];
|
DisplayClass.data[i] = (CARD8) name[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
xdmcp_start(void)
|
||||||
|
{
|
||||||
|
timeOutRtx = 0;
|
||||||
|
get_xdmcp_sock();
|
||||||
|
if (xdmcpSocket >= 0)
|
||||||
|
SetNotifyFd(xdmcpSocket, XdmcpSocketNotify, X_NOTIFY_READ, NULL);
|
||||||
|
#if defined(IPv6) && defined(AF_INET6)
|
||||||
|
if (xdmcpSocket6 >= 0)
|
||||||
|
SetNotifyFd(xdmcpSocket6, XdmcpSocketNotify, X_NOTIFY_READ, NULL);
|
||||||
|
#endif
|
||||||
|
xdmcp_timer = TimerSet(NULL, 0, 0, XdmcpTimerNotify, NULL);
|
||||||
|
send_packet();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* initialize XDMCP; create the socket, compute the display
|
* initialize XDMCP; create the socket, compute the display
|
||||||
* number, set up the state machine
|
* number, set up the state machine
|
||||||
|
@ -597,12 +608,8 @@ XdmcpInit(void)
|
||||||
XdmcpRegisterDisplayClass(defaultDisplayClass,
|
XdmcpRegisterDisplayClass(defaultDisplayClass,
|
||||||
strlen(defaultDisplayClass));
|
strlen(defaultDisplayClass));
|
||||||
AccessUsingXdmcp();
|
AccessUsingXdmcp();
|
||||||
RegisterBlockAndWakeupHandlers(XdmcpBlockHandler, XdmcpWakeupHandler,
|
|
||||||
(void *) 0);
|
|
||||||
timeOutRtx = 0;
|
|
||||||
DisplayNumber = (CARD16) atoi(display);
|
DisplayNumber = (CARD16) atoi(display);
|
||||||
get_xdmcp_sock();
|
xdmcp_start();
|
||||||
send_packet();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,12 +617,8 @@ void
|
||||||
XdmcpReset(void)
|
XdmcpReset(void)
|
||||||
{
|
{
|
||||||
state = XDM_INIT_STATE;
|
state = XDM_INIT_STATE;
|
||||||
if (state != XDM_OFF) {
|
if (state != XDM_OFF)
|
||||||
RegisterBlockAndWakeupHandlers(XdmcpBlockHandler, XdmcpWakeupHandler,
|
xdmcp_start();
|
||||||
(void *) 0);
|
|
||||||
timeOutRtx = 0;
|
|
||||||
send_packet();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -630,7 +633,7 @@ XdmcpOpenDisplay(int sock)
|
||||||
if (state != XDM_AWAIT_MANAGE_RESPONSE)
|
if (state != XDM_AWAIT_MANAGE_RESPONSE)
|
||||||
return;
|
return;
|
||||||
state = XDM_RUN_SESSION;
|
state = XDM_RUN_SESSION;
|
||||||
timeOutTime = GetTimeInMillis() + XDM_DEF_DORMANCY * 1000;
|
TimerSet(xdmcp_timer, 0, XDM_DEF_DORMANCY * 1000, XdmcpTimerNotify, NULL);
|
||||||
sessionSocket = sock;
|
sessionSocket = sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,69 +651,24 @@ XdmcpCloseDisplay(int sock)
|
||||||
isItTimeToYield = TRUE;
|
isItTimeToYield = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void
|
||||||
* called before going to sleep, this routine
|
XdmcpSocketNotify(int fd, int ready, void *data)
|
||||||
* may modify the timeout value about to be sent
|
|
||||||
* to select; in this way XDMCP can do appropriate things
|
|
||||||
* dynamically while starting up
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*ARGSUSED*/ static void
|
|
||||||
XdmcpBlockHandler(void *data, /* unused */
|
|
||||||
struct timeval **wt, void *pReadmask)
|
|
||||||
{
|
{
|
||||||
fd_set *last_select_mask = (fd_set *) pReadmask;
|
|
||||||
CARD32 millisToGo;
|
|
||||||
|
|
||||||
if (state == XDM_OFF)
|
if (state == XDM_OFF)
|
||||||
return;
|
return;
|
||||||
FD_SET(xdmcpSocket, last_select_mask);
|
receive_packet(fd);
|
||||||
#if defined(IPv6) && defined(AF_INET6)
|
|
||||||
if (xdmcpSocket6 >= 0)
|
|
||||||
FD_SET(xdmcpSocket6, last_select_mask);
|
|
||||||
#endif
|
|
||||||
if (timeOutTime == 0)
|
|
||||||
return;
|
|
||||||
millisToGo = timeOutTime - GetTimeInMillis();
|
|
||||||
if ((int) millisToGo < 0)
|
|
||||||
millisToGo = 0;
|
|
||||||
AdjustWaitForDelay(wt, millisToGo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static CARD32
|
||||||
* called after select returns; this routine will
|
XdmcpTimerNotify(OsTimerPtr timer, CARD32 time, void *arg)
|
||||||
* recognise when XDMCP packets await and
|
|
||||||
* process them appropriately
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*ARGSUSED*/ static void
|
|
||||||
XdmcpWakeupHandler(void *data, /* unused */
|
|
||||||
int i, void *pReadmask)
|
|
||||||
{
|
{
|
||||||
fd_set *last_select_mask = (fd_set *) pReadmask;
|
if (state == XDM_RUN_SESSION) {
|
||||||
|
state = XDM_KEEPALIVE;
|
||||||
if (state == XDM_OFF)
|
send_packet();
|
||||||
return;
|
|
||||||
if (i > 0) {
|
|
||||||
if (FD_ISSET(xdmcpSocket, last_select_mask)) {
|
|
||||||
receive_packet(xdmcpSocket);
|
|
||||||
FD_CLR(xdmcpSocket, last_select_mask);
|
|
||||||
}
|
|
||||||
#if defined(IPv6) && defined(AF_INET6)
|
|
||||||
if (xdmcpSocket6 >= 0 && FD_ISSET(xdmcpSocket6, last_select_mask)) {
|
|
||||||
receive_packet(xdmcpSocket6);
|
|
||||||
FD_CLR(xdmcpSocket6, last_select_mask);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else if (timeOutTime && (int) (GetTimeInMillis() - timeOutTime) >= 0) {
|
|
||||||
if (state == XDM_RUN_SESSION) {
|
|
||||||
state = XDM_KEEPALIVE;
|
|
||||||
send_packet();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
timeout();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
timeout();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -832,7 +790,7 @@ send_packet(void)
|
||||||
rtx = (XDM_MIN_RTX << timeOutRtx);
|
rtx = (XDM_MIN_RTX << timeOutRtx);
|
||||||
if (rtx > XDM_MAX_RTX)
|
if (rtx > XDM_MAX_RTX)
|
||||||
rtx = XDM_MAX_RTX;
|
rtx = XDM_MAX_RTX;
|
||||||
timeOutTime = GetTimeInMillis() + rtx * 1000;
|
TimerSet(xdmcp_timer, 0, rtx * 1000, XdmcpTimerNotify, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -847,7 +805,7 @@ XdmcpDeadSession(const char *reason)
|
||||||
state = XDM_INIT_STATE;
|
state = XDM_INIT_STATE;
|
||||||
isItTimeToYield = TRUE;
|
isItTimeToYield = TRUE;
|
||||||
dispatchException |= DE_RESET;
|
dispatchException |= DE_RESET;
|
||||||
timeOutTime = 0;
|
TimerCancel(xdmcp_timer);
|
||||||
timeOutRtx = 0;
|
timeOutRtx = 0;
|
||||||
send_packet();
|
send_packet();
|
||||||
}
|
}
|
||||||
|
@ -1391,7 +1349,7 @@ recv_alive_msg(unsigned length)
|
||||||
XdmcpReadCARD32(&buffer, &AliveSessionID)) {
|
XdmcpReadCARD32(&buffer, &AliveSessionID)) {
|
||||||
if (SessionRunning && AliveSessionID == SessionID) {
|
if (SessionRunning && AliveSessionID == SessionID) {
|
||||||
state = XDM_RUN_SESSION;
|
state = XDM_RUN_SESSION;
|
||||||
timeOutTime = GetTimeInMillis() + XDM_DEF_DORMANCY * 1000;
|
TimerSet(xdmcp_timer, 0, XDM_DEF_DORMANCY * 1000, XdmcpTimerNotify, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
XdmcpDeadSession("Alive response indicates session dead");
|
XdmcpDeadSession("Alive response indicates session dead");
|
||||||
|
|
Loading…
Reference in New Issue