Serial port to serial port copying software

Serial port to serial port copying software

Post by D'Arcy J.M. Ca » Sat, 02 Oct 1993 20:27:35

>>   I'm trying to find out whether anyone has idea for a serial-port
>>sharing program.  Basically, I have a Linux box connected to a modem
>>and a PC acting as a terminal.  I would like to be able to access the
>>modem directly from the terminal, probably by setting up an account
>Basically you open the modem port, set the line to raw mode, set stdin,
>and stdout to raw mode, fork, with one process echoing stdin to the
>modem, and the other echoing modem input to stdout.
> [...]
>    fdout = open("/dev/modem",O_WRONLY);
>    if(fork()) {
>            for(;;){
>                    read(fdin, &cc, 1);
>                    write(1, &cc, 1);
>            }
>    } else {
>            for(;;) {
>                    read(0, &cc, 1);
>                    write(fdout, &cc, 1);
>            }
>    }

>Rough but you get the idea

That's a lot of system calls.  You need to read as many characters as
possible at a time.  Of course you don't want to block either since
it is supposed to be interactive.  Here is the body of a smart read

  Turn on O_NDELAY
  read a buffer of characters (buffer size 1K for example)
  if no characters read then turn off O_NDELAY and read 1 character
  write the buffer read in either case

When you write the buffer you will either have the characters that
were waiting in the input buffer at the time (up to the maximum
buffer size in your program) or you will have the one character
you waited for.  You will find a big improvement in throughput
as well as system usage this way.

Quote:>Note Follow-ups to comp.lang.c

Why?  This is pretty system specific.  I have set followups
back to comp.linux.misc and added comp.unix.programmer.


D'Arcy Cain Consulting              |   There's no government
Toronto, Ontario, Canada            |   like no government!
+1 416 424 2871          DoD#0082   |