RPi-Serial
view release on metacpan or search on metacpan
void
tty_gets (fd, nbytes)
int fd
int nbytes
PREINIT:
char *buf;
int got = 0;
int flags;
int result;
PPCODE:
if (nbytes < 0)
croak("tty_gets: nbytes must be a non-negative integer");
/* tty_open() opens with O_NDELAY (non-blocking), which defeats the
port's VMIN/VTIME read timeout. Clear it so a read blocks up to
that timeout instead of returning EAGAIN immediately. */
flags = fcntl(fd, F_GETFL, 0);
if (flags != -1 && (flags & O_NONBLOCK))
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
Newx(buf, nbytes > 0 ? nbytes : 1, char);
while (got < nbytes) {
( run in 1.221 second using v1.01-cache-2.11-cpan-5511b514fd6 )