Hello --
I am setting up a one-wire system for my home and I ran into a problem when
trying to use owfs with ibutton link12 and a keyspan usb-serial port (full
system/environment details below). The problem appears to be related to the
fact that the com port (/dev/ttyUSB0) is opened with O_NONBLOCK which means
the write() system calls can return EWOULDBLOCK, but that return status does
not appear to be handled. I have created a patch (also below) which handles
this case for the ow_link.c code.
I wasn't sure whether there was interest in this change and if, so whether
it should be more extensive (adding fields to the statistics structure to
count how often this happens, adding it to other write routines, etc).
Please let me know what you think.
-- charles
System/Environment details:
Hardware:
+ Thinkpad T41
+ keyspan19hs (usb->serial port)
+ ibutton link12 (serial port -> 1-wire)
Software:
+ Ubuntu 7.10 Gutsy release (based on linux kernel 2.6.22)
+ keyspan driver (from 2.6.22.9)
+ owfs-2.7p4
Patch details (only modified ow_link.c in owlib):
--- ../pristine/owfs-2.7p4/module/owlib/src/c/ow_link.c 2008-03-04
18:48:36.000000000 -0800
+++ module/owlib/src/c/ow_link.c 2008-07-27 11:44:11.000000000 -0700
@@ -304,10 +304,27 @@
// COM_flush(pn) ;
//printf("Link write attempting %d bytes on
%d\n",(int)size,pn->selected_connection->file_descriptor) ;
while (left_to_write > 0) {
- ssize_t write_or_error =
write(pn->selected_connection->file_descriptor, buf,
+ ssize_t write_or_error;
+ int ewouldblock_retry_count = 0;
+ // Since the com port is opened with O_NONBLOCK
+ // for both reading and writing,
+ // then need to handle the case where a write
+ // might block and wait for the write resources
+ // to become available.
+ do {
+ LEVEL_DEBUG("erc: %d\n", ewouldblock_retry_count++);
+ // Not all versions of gcc/linux touch the
+ // errno on success, so make sure there is no
+ // garbage left in errno from a previous access
+ errno = 0;
+ write_or_error =
write(pn->selected_connection->file_descriptor, buf,
left_to_write);
- Debug_Bytes("Link write", buf, left_to_write);
- //printf("Link write = %d\n",(int)write_or_error);
+ Debug_Bytes("Link write", buf, left_to_write);
+ //printf("Link woe = %d\n",(int)write_or_error);
+ if ((write_or_error < 0) && (EWOULDBLOCK == errno))
{
+ usleep(1000);
+ }
+ } while (EWOULDBLOCK == errno);
if (write_or_error < 0) {
ERROR_CONNECT("Trouble writing data to LINK: %s\n",
SAFESTRING(pn->selected_connection->name));
STAT_ADD1_BUS(e_bus_write_errors,
pn->selected_connection);
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers