--- sourceforge.net/trunk/rdesktop/rdpdr.c 2004/01/30 14:10:32 592 +++ sourceforge.net/trunk/rdesktop/rdpdr.c 2004/02/02 07:06:55 593 @@ -49,7 +49,9 @@ DEVICE_FNS *fns; struct async_iorequest *next; /* next element in list */ -} g_iorequest; +}; + +struct async_iorequest *g_iorequest; /* Return device_id for a given handle */ int @@ -83,42 +85,27 @@ { struct async_iorequest *iorq; - iorq = &g_iorequest; - while (iorq->fd != 0) + if (g_iorequest == NULL) { - // create new element if needed - if (iorq->next == NULL) - iorq->next = - (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); - - iorq = iorq->next; + g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); + g_iorequest->fd = 0; + g_iorequest->next = NULL; } - /* first element is special since it doesn't get deleted */ - /* don't want to get io out of order */ - if (g_iorequest.fd == 0) + iorq = g_iorequest; + + while (iorq->fd != 0) { - iorq = &g_iorequest; - /* look for first occurrence of fd */ - while (iorq->next != NULL) - { - if (iorq->fd == file) - break; - iorq = iorq->next; - } - /* if same create new link at end of chain instead */ - if (iorq->fd == file) + // create new element if needed + if (iorq->next == NULL) { - while (iorq->next != NULL) - iorq = iorq->next; iorq->next = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); - iorq = iorq->next; + iorq->next->fd = 0; + iorq->next->next = NULL; } - else - iorq = &g_iorequest; /* didn't find fs use first entry */ + iorq = iorq->next; } - iorq->device = device; iorq->fd = file; iorq->id = id; @@ -329,8 +316,8 @@ case DEVICE_TYPE_DISK: - /*rw_blocking = False; */ fns = &disk_fns; + /*rw_blocking = False; */ break; case DEVICE_TYPE_SCARD: @@ -702,7 +689,7 @@ long select_timeout = 0; // Timeout value to be used for select() (in millisecons). struct async_iorequest *iorq; - iorq = &g_iorequest; + iorq = g_iorequest; while (iorq != NULL) { if (iorq->fd != 0) @@ -756,7 +743,7 @@ return; } - iorq = &g_iorequest; + iorq = g_iorequest; prev = NULL; while (iorq != NULL) { @@ -770,10 +757,16 @@ { /* Read the data */ fns = iorq->fns; + + /* never read larger chunks than 8k - chances are that it will block */ status = fns->read(iorq->fd, iorq->buffer + iorq->partial_len, - iorq->length - iorq->partial_len, - 0, &result); + (iorq->length - + iorq->partial_len) > + 8192 ? 8192 : (iorq->length - + iorq-> + partial_len), 0, + &result); iorq->partial_len += result; #if WITH_DEBUG_RDP5 DEBUG(("RDPDR: %d bytes of data read\n", result)); @@ -795,6 +788,12 @@ prev->next = iorq->next; xfree(iorq); } + else + { + // Even if NULL + g_iorequest = iorq->next; + xfree(iorq); + } } } break; @@ -803,11 +802,17 @@ { /* Write data. */ fns = iorq->fns; + + /* never write larger chunks than 8k - chances are that it will block */ status = fns->write(iorq->fd, iorq->buffer + iorq->partial_len, - iorq->length - - iorq->partial_len, 0, &result); + (iorq->length - + iorq->partial_len) > + 8192 ? 8192 : (iorq->length - + iorq-> + partial_len), 0, + &result); iorq->partial_len += result; #if WITH_DEBUG_RDP5 DEBUG(("RDPDR: %d bytes of data written\n", @@ -829,6 +834,12 @@ prev->next = iorq->next; xfree(iorq); } + else + { + // Even if NULL + g_iorequest = iorq->next; + xfree(iorq); + } } } break; @@ -866,6 +877,12 @@ prev->next = iorq->next; xfree(iorq); } + else + { + // Even if NULL + g_iorequest = iorq->next; + xfree(iorq); + } return True; }