[Nut-upsdev] [PATCH] disable nonblocking mode on serial port

Arjen de Korte nut+devel at de-korte.org
Sat Sep 27 10:53:42 UTC 2008


Citeren "Jim Paris" <jim at jtan.com>:

[...]

> It's wrong to open a device with O_NONBLOCK and then write to it and
> expect it to always succeed.

If you know that there should be room to write a single character in  
the output buffer of the UART, this isn't unreasonable to expect. The  
delays in ser_send_pace() should allow for plenty of time to empty  
even the smallest buffer, so this will always be the case.

> One needs to at deal with EAGAIN.

No, we don't. This isn't the generic case for a POSIX write() command,  
we know that we're dealing with a UART that must have at least room  
for a single character. If sufficient time has passed since the  
character was written, EAGAIN is not a proper response from the USB to  
serial driver (even if POSIX allows it).

> If we
> can agree on that we can figure out a solution that we're both happy
> with :)

I'm afraid I feel that this is more a bug in the USB to serial  
implementation, than a flaw in NUT.

> One solution would be to get rid of O_NONBLOCK as I did.

No. This fails to deal with stalled connections in case flow control  
is used. NUT drivers are single threaded, so blocking just about  
anywhere also means that the connection to the server will be affected.

> Another would be to put the write() in a loop checking for EAGAIN.

This would fail in exactly the same way as using blocking writes. Any  
loop that isn't guaranteed to exit within a predefined time is not a  
solution.

> A third is to put a select() before the write that checks for writability.

This could be an option. If the buffers are indeed empty this would be  
no-op and we would just waste a select() call for every character. But  
still I really don't think this is where the problem is. Running the  
powerpanel driver with debugging enabled at level three would help in  
finding where things go wrong.

Best regards, Arjen
-- 
Please keep list traffic on the list



More information about the Nut-upsdev mailing list