mirror of
https://github.com/GOSTSec/sgminer
synced 2025-02-02 10:04:33 +00:00
Cope with timeouts and partial reads in ztex code.
This commit is contained in:
parent
6d63229ea2
commit
280539bf98
25
libztex.c
25
libztex.c
@ -607,11 +607,19 @@ int libztex_scanDevices(struct libztex_dev_list*** devs_p)
|
|||||||
|
|
||||||
int libztex_sendHashData(struct libztex_device *ztex, unsigned char *sendbuf)
|
int libztex_sendHashData(struct libztex_device *ztex, unsigned char *sendbuf)
|
||||||
{
|
{
|
||||||
int cnt;
|
int cnt, ret;
|
||||||
|
|
||||||
if (ztex == NULL || ztex->hndl == NULL)
|
if (ztex == NULL || ztex->hndl == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
cnt = libusb_control_transfer(ztex->hndl, 0x40, 0x80, 0, 0, sendbuf, 44, 1000);
|
ret = 44;
|
||||||
|
while (ret > 0) {
|
||||||
|
cnt = libusb_control_transfer(ztex->hndl, 0x40, 0x80, 0, 0, sendbuf, ret, 1000);
|
||||||
|
if (cnt >= 0)
|
||||||
|
ret -= cnt;
|
||||||
|
else
|
||||||
|
if (cnt != LIBUSB_ERROR_TIMEOUT)
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (unlikely(cnt < 0))
|
if (unlikely(cnt < 0))
|
||||||
applog(LOG_ERR, "%s: Failed sendHashData with err %d", ztex->repr, cnt);
|
applog(LOG_ERR, "%s: Failed sendHashData with err %d", ztex->repr, cnt);
|
||||||
|
|
||||||
@ -621,7 +629,7 @@ int libztex_sendHashData(struct libztex_device *ztex, unsigned char *sendbuf)
|
|||||||
int libztex_readHashData(struct libztex_device *ztex, struct libztex_hash_data nonces[]) {
|
int libztex_readHashData(struct libztex_device *ztex, struct libztex_hash_data nonces[]) {
|
||||||
int bufsize = 12 + ztex->extraSolutions * 4;
|
int bufsize = 12 + ztex->extraSolutions * 4;
|
||||||
unsigned char *rbuf;
|
unsigned char *rbuf;
|
||||||
int cnt, i, j;
|
int cnt, i, j, ret;
|
||||||
|
|
||||||
if (ztex->hndl == NULL)
|
if (ztex->hndl == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
@ -631,7 +639,16 @@ int libztex_readHashData(struct libztex_device *ztex, struct libztex_hash_data n
|
|||||||
applog(LOG_ERR, "%s: Failed to allocate memory for reading nonces", ztex->repr);
|
applog(LOG_ERR, "%s: Failed to allocate memory for reading nonces", ztex->repr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
cnt = libusb_control_transfer(ztex->hndl, 0xc0, 0x81, 0, 0, rbuf, bufsize * ztex->numNonces, 1000);
|
ret = bufsize * ztex->numNonces;
|
||||||
|
while (ret > 0) {
|
||||||
|
cnt = libusb_control_transfer(ztex->hndl, 0xc0, 0x81, 0, 0, rbuf, ret, 1000);
|
||||||
|
if (cnt >= 0)
|
||||||
|
ret -= cnt;
|
||||||
|
else
|
||||||
|
if (cnt != LIBUSB_ERROR_TIMEOUT)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (unlikely(cnt < 0)) {
|
if (unlikely(cnt < 0)) {
|
||||||
applog(LOG_ERR, "%s: Failed readHashData with err %d", ztex->repr, cnt);
|
applog(LOG_ERR, "%s: Failed readHashData with err %d", ztex->repr, cnt);
|
||||||
free(rbuf);
|
free(rbuf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user