mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Fix incorrect handling of the return value of the poll system call
This commit is contained in:
parent
4aa36e6e91
commit
b2a8c02d1d
2 changed files with 20 additions and 1 deletions
|
|
@ -98,12 +98,17 @@ int read_poll(int fd, void *data, size_t len, int timeout)
|
||||||
if (fds.revents & POLLIN)
|
if (fds.revents & POLLIN)
|
||||||
{
|
{
|
||||||
// Read ready data
|
// Read ready data
|
||||||
|
// return value should not be 0
|
||||||
return read(fd, data, len);
|
return read(fd, data, len);
|
||||||
}
|
}
|
||||||
|
else /* if (fds.revents & (POLLERR | POLLHUP | POLLNVAL)) */
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Timeout */
|
/* Timeout */
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to calculate djb2 hash of string
|
// Function to calculate djb2 hash of string
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,9 @@ static int xmodem_1k(int sio, const void *data, size_t len, int seq)
|
||||||
rc = read_poll(sio, &resp, 1, 50);
|
rc = read_poll(sio, &resp, 1, 50);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
|
/* timeout 50 ms
|
||||||
|
resp has last received character beacuse read_poll() doesn't
|
||||||
|
destroy resp value in this case. */
|
||||||
if (resp == 'C') break;
|
if (resp == 'C') break;
|
||||||
if (resp == CAN) return ERR;
|
if (resp == CAN) return ERR;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -232,6 +235,9 @@ static int xmodem(int sio, const void *data, size_t len)
|
||||||
rc = read_poll(sio, &resp, 1, 50);
|
rc = read_poll(sio, &resp, 1, 50);
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
{
|
{
|
||||||
|
/* timeout 50 ms
|
||||||
|
resp has last received character beacuse read_poll() doesn't
|
||||||
|
destroy resp value in this case. */
|
||||||
if (resp == 'C') break;
|
if (resp == 'C') break;
|
||||||
if (resp == CAN) return ERR;
|
if (resp == CAN) return ERR;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -389,6 +395,10 @@ int start_receive(int sio)
|
||||||
{
|
{
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
else /* if (fds.revents & (POLLERR | POLLHUP | POLLNVAL)) */
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (key_hit)
|
if (key_hit)
|
||||||
return USER_CAN;
|
return USER_CAN;
|
||||||
|
|
@ -544,6 +554,10 @@ int receive_packet(int sio, struct xpacket packet, int fd)
|
||||||
while (read_poll(sio, &dummy, 1, 100) > 0) {}
|
while (read_poll(sio, &dummy, 1, 100) > 0) {}
|
||||||
return ERR;
|
return ERR;
|
||||||
}
|
}
|
||||||
|
else /* if (fds.revents & (POLLERR | POLLHUP | POLLNVAL)) */
|
||||||
|
{
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t tester = 0xff;
|
uint8_t tester = 0xff;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue