[En-Nut-Discussion] select() implementation / Re-Integration of the "devnut_select" branch

Ole Reinhardt ole.reinhardt at embedded-it.de
Sun Oct 20 23:50:57 CEST 2013

Hi Harald,

> On 13.09.2013 16:24, Ole Reinhardt wrote:
>> quite some time ago I started implementation of the posix select()
>> function for Nut/OS. The results can be found in the devnut_select
>> branch and perhaps some of you just took a look onto the new code.
> Strange, I cannot even compile the branch? Do I have to modify anything
> else?

I just updated the devnut_select_or branch. It is now merged up to the
latest trunk revision and compiles without problems (tested for CM3, ARM
and AVR).

Currently the NUTDEVICE.dev_select is currently implemented for all
drivers base on dev/usart.c.

Further will follow.

All drivers that do not support select yet have set dev_select to 0. In
this case a filedescriptor assigned to such a device would be ignored by

There is no sample application added yet, but basically it works like this:

void select_test(void)
	int      retval;
	int      fd1, fd2;
	fd_set   rfds;
	fd_set   wfds;
	fd_set   exfds;
	struct timeval tv;
	uint32_t time;

	fd1 = _fileno(stdout);
	fd2 = _fileno(stdin);

	printf("Files: %d %d\n", fd1, fd2);


	FD_SET(fd1, &wfds);
	FD_SET(fd2, &rfds);

	/* Wait up to five seconds. */
	tv.tv_sec = 5;
	tv.tv_usec = 0;

	time = NutGetMillis();
	retval = select(fd2 + 1, &rfds, &wfds, &exfds, &tv);
	/* Don't rely on the value of tv now! */

	if (retval == 0) {
		printf("Select timed out\n");
	} ellse
	if (retval < 0) {
		printf("Select error: %d\n", errno);
	} else {
		printf("Select rc: %d, time: %ld\n", retval,
		        NutGetMillis() - time);
		if (FD_ISSET(fd2, &rfds)) {
			printf("Read char: %c\n", fgetc(stdin));

kernel concepts GmbH            Tel: +49-271-771091-14
Sieghuetter Hauptweg 48         Mob: +49-177-7420433
D-57072 Siegen

More information about the En-Nut-Discussion mailing list