--- sourceforge.net/trunk/rdesktop/rdpdr.c 2004/04/16 12:20:56 660 +++ sourceforge.net/trunk/rdesktop/rdpdr.c 2004/06/15 22:17:08 710 @@ -38,6 +38,7 @@ #include #include /* opendir, closedir, readdir */ #include +#include #include "rdesktop.h" #define IRP_MJ_CREATE 0x00 @@ -54,7 +55,7 @@ #define IRP_MN_QUERY_DIRECTORY 0x01 #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 -extern char hostname[16]; +extern char g_hostname[16]; extern DEVICE_FNS serial_fns; extern DEVICE_FNS printer_fns; extern DEVICE_FNS parallel_fns; @@ -112,7 +113,7 @@ } } -BOOL +static BOOL rdpdr_handle_ok(int device, int handle) { switch (g_rdpdr_device[device].device_type) @@ -133,7 +134,7 @@ } /* Add a new io request to the table containing pending io requests so it won't block rdesktop */ -BOOL +static BOOL add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length, DEVICE_FNS * fns, uint32 total_timeout, uint32 interval_timeout, uint8 * buffer, uint32 offset) @@ -179,7 +180,7 @@ return True; } -void +static void rdpdr_send_connect(void) { uint8 magic[4] = "rDCC"; @@ -195,7 +196,7 @@ } -void +static void rdpdr_send_name(void) { uint8 magic[4] = "rDNC"; @@ -204,7 +205,7 @@ if (NULL == g_rdpdr_clientname) { - g_rdpdr_clientname = hostname; + g_rdpdr_clientname = g_hostname; } hostlen = (strlen(g_rdpdr_clientname) + 1) * 2; @@ -220,7 +221,7 @@ } /* Returns the size of the payload of the announce packet */ -int +static int announcedata_size() { int size, i; @@ -247,7 +248,7 @@ return size; } -void +static void rdpdr_send_available(void) { @@ -305,7 +306,7 @@ channel_send(s, rdpdr_channel); } -void +static void rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer, uint32 length) { @@ -691,7 +692,7 @@ buffer = NULL; } -void +static void rdpdr_send_clientcapabilty(void) { uint8 magic[4] = "rDPC"; @@ -809,6 +810,7 @@ { uint32 select_timeout = 0; // Timeout value to be used for select() (in millisecons). struct async_iorequest *iorq; + char c; iorq = g_iorequest; while (iorq != NULL) @@ -818,8 +820,16 @@ 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) && (errno == EBADF)) + 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 @@ -833,14 +843,20 @@ 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) && (errno == EBADF)) + break; + FD_SET(iorq->fd, wfds); + *n = MAX(*n, iorq->fd); break; } - *n = MAX(*n, iorq->fd); + } iorq = iorq->next;