home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
DRIVERS
/
SRC
/
ptys.lzh
/
ptyman.doc
< prev
next >
Wrap
Text File
|
1990-04-25
|
10KB
|
251 lines
Pseudo-Terminal (PTY) File-Manager
==================================
Overview:
Pseudo-Terminals (PTY's) are a kind of Interprocess
Communication (IPC), which are known on a wide variety of UN*X
computers, mostly BSD-like systems. They behave like any other SCF
devices like terminals and printer but are in fact pseudo-devices i.e.
exists only in the memory the system.
PTY's have two distinct end-points, namely server-pty and
client-pty, which behaves by default differently. A server-pty
symbolizes the terminal and a client-pty forms the connection to the
application programs. This implies, that the server-pty provides RAW
input and output whereas the client-pty can handle line-editing, echoing
and so on.
With this mechanism many programms can share one real device,
like a real terminal, via one server which multiplexes all connected
server-pty's. Something similar can be reached with the usage of pipes,
but pipes have the disadvantage of being not a tty-device with echo,
line-editing, interrupt-chars etc.
Examples:
- virtual Terminals: one program multiplexes ptys and displays the
outputs on a real Terminal (there exist a programm called 'screen'
which does exactly this).
- In a TCP/IP environment, the program 'rlogin' starts a
login-process on a pty on the remote machine.
___________________________________________________________________________
/***********\ /**************\
* * * *
* Server- * ----------> * real Device *
* Prg. * * *
\***********/ \**************/
___+ + + +_______
___/ \ \ \_______
___/ \ \________ \________
/ \ \_______ \__________
| | | |
/***********\ /***********\ /***********\ /***********\
* * * * * * * *
* 1st Prg. * * 2nd Prg. * * 3rd Prg. * * 4th Prg. *
* * * * * * * *
\***********/ \***********/ \***********/ \***********/
'|' meaning client-pty
'+' meaning server-pty
Fig. 1: Typical Server-Client Application
Implementation:
With OS9-68000 (OSK) a own File-Manager was written, which
handles both types of PTY's : the client-ptys, and the server-ptys while
using only *one* descriptor (device) for each. Server-ptys must be
opened as "/pty/any_valid_name" , client-ttys must be opened (i.e.
connected) with "/tty/any_valid_name". The Open-Call for the client-pty
will block until a server-pty with the same name is opened. PTY's can
be also implemented with the usage of a special device-driver for the
SCF, but this has serveral draw-backs :
- A System-Global Variable has to be introduced for the rendezvous
of the PTY-pairs (not implementation independent).
- For each pair of PTY's there must exist two Device-Descriptors
(waste of memory and Device-Table-entries).
- The number of PTY's pairs are limited !!
- Block-writes in RAW modus has still to be done on a char-by-char
basis with single calls to the driver, as required by the SCF
When creating a server-PTY the Filemanager searches a list of
already openend server-ptys for the same name. The name can be any
legal OS-9/68000 Filename (no distinction between upper- and
lower-case). When a identical name is found, the Filemanager return a
E_CEF-error (File already exists), otherwise the Pathdescriptor (PD) is
inserted into this list and some initialisation is done (allocating
Data-Buffers etc.).
When opening a client-PTY the Filemanager looks thru the above
mentioned list for a already openend server-pty. If found, it sets a
special pointer pointing to the PD of the server-pty. (the Filemanager
basicly distincts server-pty's and client-pty's by the value of this
pointer).
Remark:
There exist only *one* named server-pty but there can be many
client-ptys listening (although its possibly to I$DUP a
server-pty-fd).
When closing a Server-Pty, the Filemanager searches for all
client-pty's and sets the special pointer to NULL indicating a
HANGUP-condition. He also tries to send a SIGHUP-Signal (value is
changeable via the _ss_dcoff()-Call) to the last/current user of a
client-pty. Any further I/O calls to a disconnected client-pty will
issue a E_HANGUP-Error and a SIGHUP signal !
Closing a client-pty requires no special tasks but clearing all
pending Signals (e.g. pending _ss_signl() ), which is done automaticly.
Although total compatibility to a SCF-Device was intended, the
PTY-Filemanager does differ in some small aspects from the SCF. The
reason for that were some features of the SCF, which I do consider
faulty e.g. with a ReadLn-count of one the only character you can read
is CR and nothing else (:-( ).
Differences:
- a Readln-Call with a character count of 1 will return the next
character available.
- The Read-Call may behave differently: kbich and kbach will
abort with the appropriate Error-codes. No Echo, but raw-byte-transfer.
- The Pause-char, Xon-char and Xoff-char are not supported !
- Any signal < 32 and > 1 (SIGWAKE) will abort a pending I/O with an
error-code of the signal (this should be made standard).
- A close of a server-pty will only generate a SIGHUP (see SS_DCOff)
and will *not* abort the reading processes (the program 'com'
seems to have problems with that !).
Descriptions of operation:
- Read-calls:
absolute raw-read, ignores echo-parameter, but unterstands kbich and
kbach.
- Write-calls:
absolute raw-write .... but sends QUIT and INT if set.
- Writeln-calls:
recognizes upc, tabch, tabs, alf, pause and returns on recognizing
the eor-char (normaly CR). sends QUIT and INT if set.
- Readln-calls:
recognition of echo, upc, bso, bse, bspchar, eorchar, alf (when
echoing), kbich, kbach, eof, delchar, rprchar, dupchar and pause.
CAVEAT:
- A final EOR in the input-stream is not necessary and this was
deliberatly avoided !!!
- The maximum readln-count is 256 Bytes (like in the SCF). You can
specify more but the Filemanger will cut it to 256...
- GetStat-calls:
supported codes are: SS_Opt, SS_Ready, SS_EOF, SS_DevNm (returns the
name of the pty), SS_BlkRd.
- SetStat-calls:
supported codes are: SS_Opt, SS_SSig, SS_Relea, SS_EnRTS, SS_DsRTS,
SS_DCOn, SS_DCOff, SS_BlkWr.
CAVEAT:
- SS_DCOn, SS_EnRTS and SS_DsRTS are no-ops.
Not supported are null (for padding), pausechar, xon and xoff.
Description of GetStat-Codes:
- SS_Opt:
copy the first 28 Bytes of the option part to the users
(a0)-register.
- SS_Ready:
return number of chars available for reading in users d1
register, or return E_NOTRDY if no input is available.
- SS_EOF:
always returns 0 in callers d1 register (like SCF).
- SS_DevNm:
return the null-terminated name of the pty into the callers
(a0)-register.
- SS_BlkRd:
Read x (in users d2-register) Bytes into buffer, users
(a0)-register is pointing to.
Description of SetStat-Codes:
- SS_Opt:
copy the first 28 Byte from users (a0)-register into the option
part of the pathdescriptor.
- SS_SSig:
Send signal in users d2-register on receiving the next
available character. If another Process is waiting for input,
return an E_NOTRDY error.
- SS_Relea:
Clear a SS_SSig action...
- SS_EnRTS:
no-op
- SS_DsRTS:
no-op
- SS_DCOn:
no-op
- SS_DCOff:
Send Signal in users d2-register on closing the server-pty
(Carrier-lost condition). The Default signal is SIGHUP (Value: 4).
- SS_BlkWr:
Write x ( in users d2-register ) Bytes from buffer users
(a0)-register is pointing to.
- SS_Screen (Subfunction ScrOut):
Optional, like BlkWr. exists only on ST's (Cumana Implementation).
Final Thoughts:
Some tests have shown, that this Filemanager is about 100%
faster than an orthodox implementation with a special device Driver for
the SCF when doing readln/writeln calls. By using only read/write calls
some can expect even much more throughput (no line-editing stuff etc..).
BUGS:
This Filemanager seems to have problems in OSK-Versions lower
than 2.0 (-> e.g. 1.2). I think the 'openend-Path'-list isnt supported
by the Kernel (IOMan); maybe the Filemanager should do it itself ??
'tmode normal' dont work, since it takes the name returned by
DevNm as a Descriptor-module-name. This is easily changeable by returning
'pty' or 'tty' on SS_DevNm.
Things to do:
- shrinking the code
- treatment of dir-bit as in PipeMan, to see what ptys are open ?
- more lineediting (emacs-style, history ?)
- implementing the pausechar and maybe xon/xoff ?
Please send any suggestions/Bug-reports to:
Reimer Mellin
Sulenstr. 8
D-8000 Muenchen 71
UUCP: mellin@lan.informatik.tu-muenchen.dbp.de (preferred)
mellin@altger.UUCP
....!pyramid!tmpmbx!doitcr!ramsys!ram (home)