Subject: Re: How to write telnet server like program for serial port?
From: Brian Dessent <[email-masked]>
To: [email-masked]
Date: Fri, 01 Oct 2004 20:11:42 -0700

Siegfried Heintze wrote:

> I need to write a program similar to a telnet server. A telnet server
> asynchronously reads data from a socket and writes it to a
> sub-process, and asynchronously reads data from the subprocess and
> writes to a socket. My program needs to replace the subprocess with a
> serial port.
> 
> The telnet server cannot anticipate when data will arrive from the
> socket. Neither can it anticipate when data will arrive from the
> subprocess.
> 
> How can I write a similar OS vendor neutral program using Cygwin C++,
> except, instead reading and writing to a process, I read and write to
> serial port? Can I do this with a single thread? How do I read and
> write to a serial port? Can anyone point me to some sample code for
> serial port I/O? I suppose I can look at the source for telnet -- it
> probably uses the select function.

I can't give you specific answers, but if you want this to work the
general answer will be "You do it the same way you'd do it on Linux or
*BSD."

In other words, open the serial port as /dev/ttyS* and access it as a
regular filehandle just like everything else.  Use select() to determine
when things are ready to read or write, and allocate a master/slave pty
for subprocesses that expect a console.

That said, I don't know what the current state of support for select()
and serial devices is.  However, the majority of functionality that you
need should be there.  Better yet, if you run into something that
doesn't work, pare it down to a simple testcase that shows the issue
(and nothing more) and post it here, so that the serial code can be
improved.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/