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