make select() watch for errors

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2427 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.8
Stéphane Fillod, F8CFE 2008-10-27 22:20:21 +00:00
rodzic 2bdd2c910b
commit 638628e18d
1 zmienionych plików z 67 dodań i 52 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - generic file based io functions
* Copyright (c) 2000-2008 by Stephane Fillod and Frank Singleton
*
* $Id: iofunc.c,v 1.18 2008-10-26 10:47:33 fillods Exp $
* $Id: iofunc.c,v 1.19 2008-10-27 22:20:21 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -170,13 +170,11 @@ int HAMLIB_API write_block(hamlib_port_t *p, const char *txbuffer, size_t count)
int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
{
fd_set rfds;
fd_set rfds, efds;
struct timeval tv, tv_timeout;
int rd_count, total_count = 0;
int retval;
FD_ZERO(&rfds);
FD_SET(p->fd, &rfds);
/*
* Wait up to timeout ms.
@ -187,7 +185,11 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
while (count > 0) {
tv = tv_timeout; /* select may have updated it */
retval = select(p->fd+1, &rfds, NULL, NULL, &tv);
FD_ZERO(&rfds);
FD_SET(p->fd, &rfds);
efds = rfds;
retval = select(p->fd+1, &rfds, NULL, &efds, &tv);
if (retval == 0) {
dump_hex((unsigned char *) rxbuffer, total_count);
rig_debug(RIG_DEBUG_WARN, "read_block: timedout after %d chars\n",
@ -200,6 +202,11 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
"%s\n", total_count, strerror(errno));
return -RIG_EIO;
}
if (FD_ISSET(p->fd, &efds)) {
rig_debug(RIG_DEBUG_ERR, "%s: fd error after %d chars\n",
__FUNCTION__, total_count);
return -RIG_EIO;
}
/*
* grab bytes from the rig
@ -249,14 +256,11 @@ int HAMLIB_API read_block(hamlib_port_t *p, char *rxbuffer, size_t count)
int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const char *stopset,
int stopset_len)
{
fd_set rfds;
fd_set rfds, efds;
struct timeval tv, tv_timeout;
int rd_count, total_count = 0;
int retval;
FD_ZERO(&rfds);
FD_SET(p->fd, &rfds);
/*
* Wait up to timeout ms.
*/
@ -266,7 +270,11 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const
while (total_count < rxmax-1) {
tv = tv_timeout; /* select may have updated it */
retval = select(p->fd+1, &rfds, NULL, NULL, &tv);
FD_ZERO(&rfds);
FD_SET(p->fd, &rfds);
efds = rfds;
retval = select(p->fd+1, &rfds, NULL, &efds, &tv);
if (retval == 0) /* Timed out */
break;
@ -276,6 +284,13 @@ int HAMLIB_API read_string(hamlib_port_t *p, char *rxbuffer, size_t rxmax, const
__FUNCTION__, total_count, strerror(errno));
return -RIG_EIO;
}
if (FD_ISSET(p->fd, &efds)) {
rig_debug(RIG_DEBUG_ERR, "%s: fd error after %d chars\n",
__FUNCTION__, total_count);
return -RIG_EIO;
}
/*
* read 1 character from the rig, (check if in stop set)
* The file descriptor must have been set up non blocking.