From 1b6ced7cf4629c3ee33c4ae4b79f91e8e10c5413 Mon Sep 17 00:00:00 2001 From: Peter Kallden Date: Fri, 5 Mar 2004 06:48:08 +0000 Subject: [PATCH] zero handle at init. better error handling add paper status - volker milde git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@630 423420c4-83ab-492f-b58f-81f9feb106b5 --- parallel.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/parallel.c b/parallel.c index dbc6732..c8cea33 100644 --- a/parallel.c +++ b/parallel.c @@ -7,6 +7,11 @@ #include "rdesktop.h" #include #include +#include +#include +#include + +extern int errno; extern RDPDR_DEVICE g_rdpdr_device[]; @@ -55,6 +60,7 @@ parallel_enum_devices(uint32 * id, char *optarg) // set device type g_rdpdr_device[*id].device_type = DEVICE_TYPE_PARALLEL; g_rdpdr_device[*id].pdevice_data = (void *) ppar_info; + g_rdpdr_device[*id].handle = 0; count++; (*id)++; @@ -76,21 +82,25 @@ parallel_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 dispo return STATUS_ACCESS_DENIED; } + /* all read and writes should be non blocking */ + if (fcntl(parallel_fd, F_SETFL, O_NONBLOCK) == -1) + perror("fcntl"); + + ioctl(parallel_fd, LPABORT, (int) 1); + g_rdpdr_device[device_id].handle = parallel_fd; *handle = parallel_fd; - /* all read and writes should be non blocking */ - if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1) - perror("fcntl"); - return STATUS_SUCCESS; } static NTSTATUS parallel_close(HANDLE handle) { - g_rdpdr_device[get_device_index(handle)].handle = 0; + int i = get_device_index(handle); + if (i >= 0) + g_rdpdr_device[i].handle = 0; close(handle); return STATUS_SUCCESS; } @@ -105,8 +115,33 @@ parallel_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 static NTSTATUS parallel_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) { - *result = write(handle, data, length); - return STATUS_SUCCESS; + int rc = STATUS_SUCCESS; + + int n = write(handle, data, length); + if (n < 0) + { + int status; + + *result = 0; + switch (errno) + { + case EAGAIN: + rc = STATUS_DEVICE_OFF_LINE; + case ENOSPC: + rc = STATUS_DEVICE_PAPER_EMPTY; + case EIO: + rc = STATUS_DEVICE_OFF_LINE; + default: + rc = STATUS_DEVICE_POWERED_OFF; + } + if (ioctl(handle, LPGETSTATUS, &status) == 0) + { + /* coming soon: take care for the printer status */ + printf("parallel_write: status = %d, errno = %d\n", status, errno); + } + } + *result = n; + return rc; } static NTSTATUS