BFL force all code to timeout to avoid hanging
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 3189229..ff53720 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -34,13 +34,15 @@
struct device_api bitforce_api;
-#define BFopen(devpath) serial_open(devpath, 0, -1, true)
+// Code must deal with a timeout
+#define BFopen(devpath) serial_open(devpath, 0, 1, true)
static void BFgets(char *buf, size_t bufLen, int fd)
{
- do
+ do {
+ buf[0] = '\0';
--bufLen;
- while (likely(bufLen && read(fd, buf, 1) == 1 && (buf++)[0] != '\n'));
+ } while (likely(bufLen && read(fd, buf, 1) == 1 && (buf++)[0] != '\n'));
buf[0] = '\0';
}
@@ -72,7 +74,7 @@ static bool bitforce_detect_one(const char *devpath)
BFwrite(fdDev, "ZGX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
if (unlikely(!pdevbuf[0])) {
- applog(LOG_ERR, "BFL: Error reading (ZGX)");
+ applog(LOG_ERR, "BFL: Error reading/timeout (ZGX)");
return 0;
}
@@ -200,7 +202,7 @@ void bitforce_init(struct cgpu_info *bitforce)
if (unlikely(!pdevbuf[0])) {
mutex_unlock(&bitforce->device_mutex);
- applog(LOG_ERR, "BFL%i: Error reading (ZGX)", bitforce->device_id);
+ applog(LOG_ERR, "BFL%i: Error reading/timeout (ZGX)", bitforce->device_id);
return;
}
@@ -240,7 +242,7 @@ static bool bitforce_get_temp(struct cgpu_info *bitforce)
mutex_unlock(&bitforce->device_mutex);
if (unlikely(!pdevbuf[0])) {
- applog(LOG_ERR, "BFL%i: Error: Get temp returned empty string", bitforce->device_id);
+ applog(LOG_ERR, "BFL%i: Error: Get temp returned empty string/timed out", bitforce->device_id);
bitforce->temp = 0;
return false;
}
@@ -328,7 +330,7 @@ re_send:
}
if (unlikely(!pdevbuf[0])) {
- applog(LOG_ERR, "BFL%i: Error: Send block data returned empty string", bitforce->device_id);
+ applog(LOG_ERR, "BFL%i: Error: Send block data returned empty string/timed out", bitforce->device_id);
return false;
}
diff --git a/fpgautils.c b/fpgautils.c
index 0ebee7f..07b3fe3 100644
--- a/fpgautils.c
+++ b/fpgautils.c
@@ -178,7 +178,8 @@ serial_open(const char*devpath, unsigned long baud, signed short timeout, bool p
SetCommConfig(hSerial, &comCfg, sizeof(comCfg));
- const DWORD ctoms = (timeout == -1) ? 30000 : (timeout * 100);
+ // Code must specify a valid timeout value (0 means don't timeout)
+ const DWORD ctoms = (timeout * 100);
COMMTIMEOUTS cto = {ctoms, 0, ctoms, 0, ctoms};
SetCommTimeouts(hSerial, &cto);
@@ -230,10 +231,9 @@ serial_open(const char*devpath, unsigned long baud, signed short timeout, bool p
my_termios.c_oflag &= ~OPOST;
my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
- if (timeout >= 0) {
- my_termios.c_cc[VTIME] = (cc_t)timeout;
- my_termios.c_cc[VMIN] = 0;
- }
+ // Code must specify a valid timeout value (0 means don't timeout)
+ my_termios.c_cc[VTIME] = (cc_t)timeout;
+ my_termios.c_cc[VMIN] = 0;
tcsetattr(fdDev, TCSANOW, &my_termios);
if (purge)