[En-Nut-Discussion] Device driver use patterns

Ralph Mason ralph.mason at telogis.com
Tue Jun 24 22:36:58 CEST 2003

I noticed a bug in the PPP driver code which got me to thinking how
difficult it is to avoid such a bug using in NutOS.

The basic thing is that when you call write (or NutDeviceWrite or
NutIfWrite) it can return having written less than you asked.

So you need to *every* time you call write have code that checks


void write_my_buffer(FILE* f,u_char* buff, int len){

	while ( len ){
		int written= _write(f,buff,len);

		if (written == len )

		len -= written;

Which seems wholly inefficient to me.

The UART driver implement a tx_complete event, so it seems possible to have
a write that you can count on to write all your bytes, rather than having to
use code like the above every time.

Perhaps I missed something obvious here, and this is a non issue.


Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003

More information about the En-Nut-Discussion mailing list