From 2df54194b128f540083337c08024b783971d0eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C3=85strand?= Date: Mon, 19 Apr 2004 08:24:54 +0000 Subject: [PATCH] rdpdr_add_fds: Corrected patch that prevents adding invalid FDs to the select FD sets. git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@672 423420c4-83ab-492f-b58f-81f9feb106b5 --- rdpdr.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/rdpdr.c b/rdpdr.c index ccfbbe2..0880077 100644 --- a/rdpdr.c +++ b/rdpdr.c @@ -60,7 +60,7 @@ extern DEVICE_FNS printer_fns; extern DEVICE_FNS parallel_fns; extern DEVICE_FNS disk_fns; extern FILEINFO g_fileinfo[]; - + static VCHANNEL *rdpdr_channel; /* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */ @@ -814,14 +814,21 @@ rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, BOOL * t iorq = g_iorequest; while (iorq != NULL) { - /* We need to test that the fd is still valid */ - if ((iorq->fd != 0) && (read(iorq->fd, &c, 0) == 0)) + if (iorq->fd != 0) { switch (iorq->major) { case IRP_MJ_READ: + /* Is this FD valid? FDs will + be invalid when + reconnecting. FIXME: Real + support for reconnects. */ + + if (read(iorq->fd, &c, 0) != 0) + break; FD_SET(iorq->fd, rfds); + *n = MAX(*n, iorq->fd); // Check if io request timeout is smaller than current (but not 0). if (iorq->timeout @@ -835,14 +842,20 @@ rdpdr_add_fds(int *n, fd_set * rfds, fd_set * wfds, struct timeval *tv, BOOL * t tv->tv_usec = (select_timeout % 1000) * 1000; *timeout = True; } + break; case IRP_MJ_WRITE: + /* FD still valid? See above. */ + if (write(iorq->fd, &c, 0) != 0) + break; + FD_SET(iorq->fd, wfds); + *n = MAX(*n, iorq->fd); break; } - *n = MAX(*n, iorq->fd); + } iorq = iorq->next;