mirror of
https://github.com/3cky/mbusd.git
synced 2024-11-14 10:15:17 +01:00
Fix for "Resource temporarily unavailable" error in tty read() (#78)
This commit is contained in:
parent
4cd68c1bb8
commit
1efb812013
24
src/conn.c
24
src/conn.c
@ -227,7 +227,7 @@ conn_read(int d, void *buf, size_t nbytes)
|
||||
{ /* trying read from descriptor while breaked by signals */
|
||||
rc = read(d, buf, nbytes);
|
||||
} while (rc == -1 && errno == EINTR);
|
||||
return (rc < 0) ? RC_ERR : rc;
|
||||
return (rc < 0) ? (errno == EAGAIN ? RC_EAGAIN : RC_ERR) : rc;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
@ -622,13 +622,22 @@ conn_loop(void)
|
||||
}
|
||||
rc = conn_read(tty.fd, tty.rxbuf + tty.ptrbuf,
|
||||
tty.rxlen - tty.ptrbuf + tty.rxoffset);
|
||||
if (rc <= 0)
|
||||
if (rc == RC_EAGAIN)
|
||||
{ /* some tty devices seem to be set as ready to be read by select()
|
||||
while no data is available (see #78) */
|
||||
#ifdef LOG
|
||||
logw(5, "tty: read(): no data available");
|
||||
#endif
|
||||
}
|
||||
else if (rc <= 0)
|
||||
{ /* error - make attempt to reinitialize serial port */
|
||||
#ifdef LOG
|
||||
logw(0, "tty: error in read() (%s)", rc ? strerror(errno) : "port closed");
|
||||
#endif
|
||||
tty_reinit();
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG
|
||||
logw(7, "tty: read %d bytes", rc);
|
||||
#endif
|
||||
@ -672,9 +681,18 @@ conn_loop(void)
|
||||
if (tty.ptrbuf == tty.rxlen + tty.rxoffset)
|
||||
state_tty_set(&tty, TTY_PROC);
|
||||
}
|
||||
}
|
||||
else if (tty.state != TTY_PROC)
|
||||
{ /* drop unexpected tty data */
|
||||
if ((rc = conn_read(tty.fd, tty.rxbuf, BUFSIZE)) <= 0)
|
||||
rc = conn_read(tty.fd, tty.rxbuf, BUFSIZE);
|
||||
if (rc == RC_EAGAIN)
|
||||
{ /* some tty devices seem to be set as ready to be read by select()
|
||||
while no data is available (see #78) */
|
||||
#ifdef LOG
|
||||
logw(5, "tty: read(): no data available");
|
||||
#endif
|
||||
}
|
||||
else if (rc <= 0)
|
||||
{ /* error - make attempt to reinitialize serial port */
|
||||
#ifdef LOG
|
||||
logw(0, "tty: error in read() (%s)", rc ? strerror(errno) : "port closed");
|
||||
|
@ -84,6 +84,7 @@
|
||||
#define RC_TIMEOUT -3
|
||||
#define RC_AOPEN -4
|
||||
#define RC_ACLOSE -5
|
||||
#define RC_EAGAIN -6
|
||||
|
||||
/* Internal string buffers size */
|
||||
#if defined(PATH_MAX)
|
||||
|
Loading…
Reference in New Issue
Block a user