From: ibr@kz-easy.com
To: linux-kernel@vger.kernel.org
Subject: EOF from the N_TTY ldisc intended?
Date: Thu, 12 Jun 2008 15:36:50 +0600 (ALMT) [thread overview]
Message-ID: <40326.192.35.17.30.1213263410.squirrel@admin.kz-easy.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 549 bytes --]
Hello,
I have a program reading multiple bytes one by one after a select from a
serial port opened in non-blocking mode. If I send one byte to that port,
the first read delivers it, and the second one returns zero. The program
treats this as the end of file and exits. Is this behavior of the default
line discipline intended? I would expect it to return -EAGAIN if there is
no more data in the receive queue.
I'm attaching a sample program.
Please CC to me, I'm not subscribed.
Thanks in advance,
--
Baurzhan Ismagulov
http://www.kz-easy.com/
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: b.c --]
[-- Type: text/x-csrc; name="b.c", Size: 1137 bytes --]
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
static int
dev_init(int fd)
{
struct termios t;
t.c_iflag = IGNBRK | IGNPAR | INPCK;
t.c_oflag = 0;
t.c_cflag = B57600 | CLOCAL | CREAD | CS8 | PARENB;
t.c_lflag = 0;
memset(t.c_cc, _POSIX_VDISABLE, NCCS);
t.c_cc[VMIN] = 0;
t.c_cc[VTIME] = 0;
if (tcsetattr(fd, TCSANOW, &t) == -1) {
perror("tcsetattr");
exit(2);
}
return 0;
}
static int
dev_open(const char *name)
{
int fd = open(name, O_RDWR | O_NONBLOCK);
if (fd == -1) {
perror("open");
exit(2);
}
return fd;
}
static ssize_t
dev_read(int fd, void *buf, size_t count)
{
ssize_t ret = read(fd, buf, count);
if (ret == -1) {
perror("read");
exit(2);
}
printf("%s: %d\n", __FUNCTION__, ret);
return ret;
}
int
main(void)
{
int fd = dev_open("/dev/ttyS0");
dev_init(fd);
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
if (select(fd + 1, &rfds, NULL, NULL, NULL) == -1) {
perror("select");
exit(2);
}
char buf;
dev_read(fd, &buf, 1);
dev_read(fd, &buf, 1);
return 0;
}
reply other threads:[~2008-06-12 9:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=40326.192.35.17.30.1213263410.squirrel@admin.kz-easy.com \
--to=ibr@kz-easy.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®