[comp.sys.mac.programmer] LSC and serial ports

kw1r+@andrew.cmu.edu (Kevin Whitley) (12/15/88)

I recently did work with serial ports in LSC and thought I'd report on my
experience.

The connection to the serial ports via the stdio library works quite nicely and
makes programming with the serial ports much less of a headache than before.
BUT, there are two bugs, one very serious, in the implementation of stdio
support of the ports.

1) (the serious one)  It is not possible to read from a serial port.  File reads
go through the routine read_into_buffer in stdfilebuf.c when the stdio file
buffer is exhausted.  One of the first thing that read_into_buffer does is to
call Set_file_pos (so that the read starts in the right place).  Set_file_pos
proceeds to call PBSetFPos - which fails on a serial port.

I patched this by putting the line

if (who->refnum < 0) return(0) /* don't set file position for driver (serial
port) */

at the start of the routine Set_file_pos.  This is not entirely satisfactory,
but it works.


2) (the less serious one)  When you call fclose on a FILE pointer which refers
to a serial port, the space in the _file array is not reclaimed.  So if you open
& close a serial port repeatedly, the file table fill up and calls to fopen
eventually fail due to lack of space.  The problem here is in the routine fclose
in stdopen.c.  If you look through it you will see that when closing serial
files (cases AinRefNum, BinRefNum, AoutRefNum and BoutRefNum) who->InUse is
never reset to false.  I fixed this problem simply by adding

who->InUse = false;  /* mark entry not in use anymore */

in the code for the serial port (AinRefNum, etc.) case.


I found (and successfully fixed) these problems in LSC version 2.x libraries.
The code in the version 3.0 libraries looks like it has the same problems,
though I have not tried it yet.

Kevin Whitley
kw1r@andrew.cmu.edu