Re: XForms: Creating a progress-counter in xforms

Steve Lamont (
Fri, 4 Jul 97 07:35:41 PDT

To subscribers of the xforms list from (Steve Lamont) :

> I looked at the documentation and came accros the fl_add_io_callback()
> function. However I don't quite know how to use it. ...
> ... The data stream
> sent is a binary data flow and has no termination character, so that
> makes it impossible to look for a specific character.

You don't need to. Simply read until there's no further data on the
descriptor -- you can use the select() system call to determine this,
or just read a block, process it, and return.

The following code sketches out a possible implementation of the first

int fd = open( your_device, O_RDONLY );

fl_add_io_callback( fd, FL_READ,
your_callback, ( void *) your_data );


void your_callback( int fd, void *data )


fd_set read_fds;
static timeval timeout = { 0, 0 };

do {

char buffer[BUFSIZE];
int n = read( fd, buffer, BUFSIZE );

if ( n > 0 )
process_the_buffer( buffer, n );
handle_eof_or_error_condition( n );

* Now set up the descriptor table for the select().

FD_ZERO( &read_fds );
FD_SET( fd, &readfds );

} while ( select( getdtablesize(),
&readfds, NULL, NULL, &timeout ) > 0 );


The file descriptor should, as the manual says, be connected to a pipe
or a socket. Reading from a file using this method will simply result
in the program blocking interaction until the entire file is read
since the file descriptor will always be ready to read.

Refer to the man pages for the select() and getdtablesize() system
calls for details. You may also need to do some ioctl() or fcntl()
calls and fiddle with the open() flags to set up your input file
descriptor for non-blocking input.

The Stevens advanced programming books (there are two, one published
by Prentice-Hall and the other, I believe, by Addison-Wesley) will be
a great help in learning the intricacies of asynchronous I/O

Sorry, but I don't remember the exact titles -- I'm at home today and
my library is mostly at my lab. You may want to check the archives of
this mailing list -- I've given the full titles and ISBNs before.
These are wonderful books and, IMHO, necessary parts of any working
Unix programmer's reference library (Hey, Stevens! My kickback check
is late this month! :-) :-) -- seriously, I have no financial
connection with either the author or the publishers -- I just like the
books and refer to them often).

To unsubscribe, send the message "unsubscribe" to or see
Xforms Home Page:
List Archive: