Redo when TEST UNIT READY failed

Redo when read returns with 0 bytes (non-SCSI only)
merge-requests/1/head
Peter Kirchgessner 2003-10-09 19:34:57 +00:00
rodzic 3e5bec5925
commit 2549e5bf8c
1 zmienionych plików z 56 dodań i 18 usunięć

Wyświetl plik

@ -42,6 +42,15 @@
HP Scanner Control Language (SCL). HP Scanner Control Language (SCL).
*/ */
/*
$Log$
Revision 1.12 2003/10/09 19:34:57 kig-guest
Redo when TEST UNIT READY failed
Redo when read returns with 0 bytes (non-SCSI only)
*/
/* /*
#define STUBS #define STUBS
extern int sanei_debug_hp;*/ extern int sanei_debug_hp;*/
@ -166,10 +175,25 @@ hp_nonscsi_read (HpScsi this, hp_byte_t *data, size_t *len, HpConnect connect,
int UNUSEDARG isResponse) int UNUSEDARG isResponse)
{int n = -1; {int n = -1;
static int retries = -1;
size_t save_len = *len;
SANE_Status status = SANE_STATUS_GOOD; SANE_Status status = SANE_STATUS_GOOD;
if (*len <= 0) return SANE_STATUS_GOOD; if (*len <= 0) return SANE_STATUS_GOOD;
if (retries < 0) /* Read environment */
{char *eptr = getenv ("SANE_HP_RDREDO");
retries = 1; /* Set default value */
if (eptr != NULL)
{
if (sscanf (eptr, "%d", &retries) != 1) retries = 1; /* Restore default */
else if (retries < 0) retries = 0; /* Allow no retries here */
}
}
for (;;) /* Retry on EOF */
{
switch (connect) switch (connect)
{ {
case HP_CONNECT_DEVICE: case HP_CONNECT_DEVICE:
@ -193,6 +217,11 @@ hp_nonscsi_read (HpScsi this, hp_byte_t *data, size_t *len, HpConnect connect,
n = -1; n = -1;
break; break;
} }
if ((n != 0) || (retries <= 0)) break;
retries--;
usleep (100*1000); /* sleep 0.1 seconds */
*len = save_len; /* Restore value */
}
if (n == 0) return SANE_STATUS_EOF; if (n == 0) return SANE_STATUS_EOF;
else if (n < 0) return SANE_STATUS_IO_ERROR; else if (n < 0) return SANE_STATUS_IO_ERROR;
@ -386,13 +415,22 @@ sanei_hp_scsi_new (HpScsi * newp, const char * devname)
DBG(3, "vendor=%s, model=%s, rev=%s\n", vendor, model, rev); DBG(3, "vendor=%s, model=%s, rev=%s\n", vendor, model, rev);
} }
DBG(3, "scsi_new: sending TEST_UNIT_READY\n"); DBG(3, "scsi_new: sending TEST_UNIT_READY\n");
status = sanei_scsi_cmd(new->fd, tur_cmd, 6, 0, 0); status = sanei_scsi_cmd(new->fd, tur_cmd, 6, 0, 0);
if (FAILED(status)) if (FAILED(status))
{ {
DBG(1, "hp_scsi_open: test unit ready failed (%s)\n", DBG(1, "hp_scsi_open: test unit ready failed (%s)\n",
sane_strstatus(status)); sane_strstatus(status));
usleep (500*1000); /* Wait 0.5 seconds */
DBG(3, "scsi_new: sending TEST_UNIT_READY second time\n");
status = sanei_scsi_cmd(new->fd, tur_cmd, 6, 0, 0);
}
if (FAILED(status))
{
DBG(1, "hp_scsi_open: test unit ready failed (%s)\n",
sane_strstatus(status));
sanei_scsi_close(new->fd); sanei_scsi_close(new->fd);
sanei_hp_free(new); sanei_hp_free(new);
return status; /* Fix problem with non-scanner devices */ return status; /* Fix problem with non-scanner devices */