49 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
50 |
|
|
51 |
struct async_iorequest *next; /* next element in list */ |
struct async_iorequest *next; /* next element in list */ |
52 |
} g_iorequest; |
}; |
53 |
|
|
54 |
|
struct async_iorequest *g_iorequest; |
55 |
|
|
56 |
/* Return device_id for a given handle */ |
/* Return device_id for a given handle */ |
57 |
int |
int |
85 |
{ |
{ |
86 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
87 |
|
|
88 |
iorq = &g_iorequest; |
if (g_iorequest == NULL) |
|
while (iorq->fd != 0) |
|
89 |
{ |
{ |
90 |
// create new element if needed |
g_iorequest = (struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
91 |
if (iorq->next == NULL) |
g_iorequest->fd = 0; |
92 |
iorq->next = |
g_iorequest->next = NULL; |
|
(struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
|
|
|
|
|
iorq = iorq->next; |
|
93 |
} |
} |
94 |
|
|
95 |
/* first element is special since it doesn't get deleted */ |
iorq = g_iorequest; |
96 |
/* don't want to get io out of order */ |
|
97 |
if (g_iorequest.fd == 0) |
while (iorq->fd != 0) |
98 |
{ |
{ |
99 |
iorq = &g_iorequest; |
// create new element if needed |
100 |
/* look for first occurrence of fd */ |
if (iorq->next == NULL) |
|
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) |
|
101 |
{ |
{ |
|
while (iorq->next != NULL) |
|
|
iorq = iorq->next; |
|
102 |
iorq->next = |
iorq->next = |
103 |
(struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
(struct async_iorequest *) xmalloc(sizeof(struct async_iorequest)); |
104 |
iorq = iorq->next; |
iorq->next->fd = 0; |
105 |
|
iorq->next->next = NULL; |
106 |
} |
} |
107 |
else |
iorq = iorq->next; |
|
iorq = &g_iorequest; /* didn't find fs use first entry */ |
|
108 |
} |
} |
|
|
|
109 |
iorq->device = device; |
iorq->device = device; |
110 |
iorq->fd = file; |
iorq->fd = file; |
111 |
iorq->id = id; |
iorq->id = id; |
220 |
rdp_out_unistr(s, printerinfo->printer, printerlen - 2); |
rdp_out_unistr(s, printerinfo->printer, printerlen - 2); |
221 |
out_uint8a(s, printerinfo->blob, bloblen); |
out_uint8a(s, printerinfo->blob, bloblen); |
222 |
|
|
223 |
xfree(printerinfo->blob); /* Blob is sent twice if reconnecting */ |
if (printerinfo->blob) |
224 |
|
xfree(printerinfo->blob); /* Blob is sent twice if reconnecting */ |
225 |
break; |
break; |
226 |
default: |
default: |
227 |
out_uint32(s, 0); |
out_uint32(s, 0); |
317 |
|
|
318 |
case DEVICE_TYPE_DISK: |
case DEVICE_TYPE_DISK: |
319 |
|
|
|
/*rw_blocking = False; */ |
|
320 |
fns = &disk_fns; |
fns = &disk_fns; |
321 |
|
rw_blocking = False; |
322 |
break; |
break; |
323 |
|
|
324 |
case DEVICE_TYPE_SCARD: |
case DEVICE_TYPE_SCARD: |
690 |
long select_timeout = 0; // Timeout value to be used for select() (in millisecons). |
long select_timeout = 0; // Timeout value to be used for select() (in millisecons). |
691 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
692 |
|
|
693 |
iorq = &g_iorequest; |
iorq = g_iorequest; |
694 |
while (iorq != NULL) |
while (iorq != NULL) |
695 |
{ |
{ |
696 |
if (iorq->fd != 0) |
if (iorq->fd != 0) |
737 |
DEVICE_FNS *fns; |
DEVICE_FNS *fns; |
738 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
739 |
struct async_iorequest *prev; |
struct async_iorequest *prev; |
740 |
|
uint32 req_size = 0; |
741 |
|
|
742 |
if (timed_out) |
if (timed_out) |
743 |
{ |
{ |
745 |
return; |
return; |
746 |
} |
} |
747 |
|
|
748 |
iorq = &g_iorequest; |
iorq = g_iorequest; |
749 |
prev = NULL; |
prev = NULL; |
750 |
while (iorq != NULL) |
while (iorq != NULL) |
751 |
{ |
{ |
|
|
|
752 |
if (iorq->fd != 0) |
if (iorq->fd != 0) |
753 |
{ |
{ |
754 |
switch (iorq->major) |
switch (iorq->major) |
758 |
{ |
{ |
759 |
/* Read the data */ |
/* Read the data */ |
760 |
fns = iorq->fns; |
fns = iorq->fns; |
761 |
|
|
762 |
|
req_size = |
763 |
|
(iorq->length - iorq->partial_len) > |
764 |
|
8192 ? 8192 : (iorq->length - |
765 |
|
iorq->partial_len); |
766 |
|
/* never read larger chunks than 8k - chances are that it will block */ |
767 |
status = fns->read(iorq->fd, |
status = fns->read(iorq->fd, |
768 |
iorq->buffer + iorq->partial_len, |
iorq->buffer + iorq->partial_len, |
769 |
iorq->length - iorq->partial_len, |
req_size, 0, &result); |
|
0, &result); |
|
770 |
iorq->partial_len += result; |
iorq->partial_len += result; |
771 |
|
|
772 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
773 |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
DEBUG(("RDPDR: %d bytes of data read\n", result)); |
774 |
#endif |
#endif |
775 |
/* only delete link if all data has been transfered */ |
/* only delete link if all data has been transfered */ |
776 |
if (iorq->partial_len == iorq->length) |
/* or if result was 0 and status success - EOF */ |
777 |
|
if ((iorq->partial_len == iorq->length) || |
778 |
|
(result == 0)) |
779 |
{ |
{ |
780 |
|
#if WITH_DEBUG_RDP5 |
781 |
|
DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length)); |
782 |
|
#endif |
783 |
/* send the data */ |
/* send the data */ |
784 |
status = STATUS_SUCCESS; |
status = STATUS_SUCCESS; |
785 |
rdpdr_send_completion(iorq->device, |
rdpdr_send_completion(iorq->device, |
786 |
iorq->id, status, |
iorq->id, status, |
787 |
iorq->length, |
iorq->partial_len, |
788 |
iorq->buffer, result); |
iorq->buffer, |
789 |
|
iorq->partial_len); |
790 |
xfree(iorq->buffer); |
xfree(iorq->buffer); |
791 |
iorq->fd = 0; |
iorq->fd = 0; |
792 |
if (prev != NULL) |
if (prev != NULL) |
794 |
prev->next = iorq->next; |
prev->next = iorq->next; |
795 |
xfree(iorq); |
xfree(iorq); |
796 |
} |
} |
797 |
|
else |
798 |
|
{ |
799 |
|
// Even if NULL |
800 |
|
g_iorequest = iorq->next; |
801 |
|
xfree(iorq); |
802 |
|
} |
803 |
} |
} |
804 |
} |
} |
805 |
break; |
break; |
808 |
{ |
{ |
809 |
/* Write data. */ |
/* Write data. */ |
810 |
fns = iorq->fns; |
fns = iorq->fns; |
811 |
|
|
812 |
|
req_size = |
813 |
|
(iorq->length - iorq->partial_len) > |
814 |
|
8192 ? 8192 : (iorq->length - |
815 |
|
iorq->partial_len); |
816 |
|
|
817 |
|
/* never write larger chunks than 8k - chances are that it will block */ |
818 |
status = fns->write(iorq->fd, |
status = fns->write(iorq->fd, |
819 |
iorq->buffer + |
iorq->buffer + |
820 |
iorq->partial_len, |
iorq->partial_len, req_size, 0, |
821 |
iorq->length - |
&result); |
|
iorq->partial_len, 0, &result); |
|
822 |
iorq->partial_len += result; |
iorq->partial_len += result; |
823 |
#if WITH_DEBUG_RDP5 |
#if WITH_DEBUG_RDP5 |
824 |
DEBUG(("RDPDR: %d bytes of data written\n", |
DEBUG(("RDPDR: %d bytes of data written\n", |
825 |
result)); |
result)); |
826 |
#endif |
#endif |
827 |
/* only delete link if all data has been transfered */ |
/* only delete link if all data has been transfered */ |
828 |
if (iorq->partial_len == iorq->length) |
/* or we couldn't write */ |
829 |
|
if ((iorq->partial_len == iorq->length) |
830 |
|
|| (result == 0)) |
831 |
{ |
{ |
832 |
|
#if WITH_DEBUG_RDP5 |
833 |
|
DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length)); |
834 |
|
#endif |
835 |
/* send a status success */ |
/* send a status success */ |
836 |
status = STATUS_SUCCESS; |
status = STATUS_SUCCESS; |
837 |
rdpdr_send_completion(iorq->device, |
rdpdr_send_completion(iorq->device, |
838 |
iorq->id, status, |
iorq->id, status, |
839 |
iorq->length, "", 1); |
iorq->partial_len, (uint8*)"", |
840 |
|
1); |
841 |
|
|
842 |
xfree(iorq->buffer); |
xfree(iorq->buffer); |
843 |
iorq->fd = 0; |
iorq->fd = 0; |
846 |
prev->next = iorq->next; |
prev->next = iorq->next; |
847 |
xfree(iorq); |
xfree(iorq); |
848 |
} |
} |
849 |
|
else |
850 |
|
{ |
851 |
|
// Even if NULL |
852 |
|
g_iorequest = iorq->next; |
853 |
|
xfree(iorq); |
854 |
|
} |
855 |
} |
} |
856 |
} |
} |
857 |
break; |
break; |
872 |
struct async_iorequest *iorq; |
struct async_iorequest *iorq; |
873 |
struct async_iorequest *prev; |
struct async_iorequest *prev; |
874 |
|
|
875 |
iorq = &g_iorequest; |
iorq = g_iorequest; |
876 |
prev = NULL; |
prev = NULL; |
877 |
while (iorq != NULL) |
while (iorq != NULL) |
878 |
{ |
{ |
881 |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
if ((iorq->fd == fd) && (major == 0 || iorq->major == major)) |
882 |
{ |
{ |
883 |
result = 0; |
result = 0; |
884 |
rdpdr_send_completion(iorq->device, iorq->id, status, result, "", 1); |
rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8*)"", 1); |
885 |
xfree(iorq->buffer); |
xfree(iorq->buffer); |
886 |
iorq->fd = 0; |
iorq->fd = 0; |
887 |
if (prev != NULL) |
if (prev != NULL) |
889 |
prev->next = iorq->next; |
prev->next = iorq->next; |
890 |
xfree(iorq); |
xfree(iorq); |
891 |
} |
} |
892 |
|
else |
893 |
|
{ |
894 |
|
// Even if NULL |
895 |
|
g_iorequest = iorq->next; |
896 |
|
xfree(iorq); |
897 |
|
} |
898 |
return True; |
return True; |
899 |
} |
} |
900 |
|
|