mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* EOF from the N_TTY ldisc intended?
@ 2008-06-12  9:36 ibr
  0 siblings, 0 replies; only message in thread
From: ibr @ 2008-06-12  9:36 UTC (permalink / raw)
  To: linux-kernel

[-- 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;
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-12  9:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-12  9:36 EOF from the N_TTY ldisc intended? ibr

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®