This section describes the following GT.M I/O commands:
The OPEN command establishes a connection from a GT.M process to a device.
The format of the OPEN command is:
O[PEN][:tvexpr] expr[:[(keyword[=expr][:...])][:numexpr][:expr]][,...]
In M mode, the OPEN command ignores ICHSET, OCHSET, CHSET, and PAD device parameters.
set sd="report.dat" open sd:newversion
This OPENs a NEWVERSION of a sequential disk file named report.dat for both read and write access.
![]() | Note |
---|---|
If an APPEND is combined with a SEEK deviceparameter the APPEND is done first - regardless of deviceparameter order. |
set sd="foo.txt" open sd:(append:recordsize=70:wrap) use sd
This example open file foo.txt and positions the file pointer at the end of the file.
For information on using the ATTACH with USE, refer to a??ATTACHa?? in the USE Deviceparameters section.
Example:
open tcpdev:(ichset="M":connect=hostname_":"_portno_":TCP":attach="client"):timeout:"SOCKET"
This example uses the ATTACH deviceparameter to specify "client" as the identifier of the newly created socket. Note that GT.M recognizes ICHSET only in UTF-8 mode.
CHSET=expr Applies to: All devices
Establishes a common encoding for both input and output devices for the device being OPENed in UTF-8 mode. The value of the expression can be M, UTF-8, UTF-16, UTF-16LE, or UTF-16BE. For more information, refer to a??ICHSETa?? and a??OCHSETa??.
Specifies the UNIX command the newly created shell process performs. An invalid command value triggers an error in the new process, not the process issuing the OPEN. This can make diagnosis difficult - see the a??PARSEa?? deviceparameter for potential assistance.
![]() | Note |
---|---|
CONNECT is not compatible with LISTEN. |
open tcpdev:(connect=hostname_":"_portno_":TCP":attach="client":ioerror="TRAP"):timeout:"SOCKET"
[NO]DELIMITER=expr Applies to: SOC
expr is a string where the following characters have special interpretation:
![]() | Note |
---|---|
expr "ab:/:://:bc" is interpreted as four delimiters, which are "ab", ":", "/", and "bc". One socket can have 0-64 delimiters and each delimiter can contain 1-64 characters. |
open tcpdev:(connect=host_":"_portno_":TCP":delim=$c(13):attach="client"):timeout:"SOCKET"
This command specifies $CHAR(13) as the delimiter for the socket tcpdev.
EXCEPTION=expr Applies to: All devices
GTM>do ^FREAD FREAD; zprint ^FREAD read "File > ",sd set retry=0 set $ztrap="BADAGAIN" open sd:(readonly:exception="do BADOPEN") use sd:exception="goto EOF" for use sd read x use $principal write x,! EOF; if '$zeof zmessage +$zstatus close sd quit BADOPEN; set retry=retry+1 if retry=2 open sd if retry=4 halt if $piece($zstatus,",",1)=2 do . write !,"The file ",sd," does not exist. Retrying in about 2 seconds ..." . hang 2.1 . quit if $piece($zstatus,",",1)=13 do . write !,"The file ",sd," is not accessible. Retrying in about 3 seconds ..." . hang 3.1 . quit quit BADAGAIN; w !,"BADAGAIN",! File >
[NO]FIXED Applies to: SD FIFO PIPE
![]() | Note |
---|---|
FIXED length records do not implicitly use embedded record terminators such as line feeds. |
![]() | Note |
---|---|
PAD is effective only for devices opened with a CHSET related to UnicodeA(R) characters. In M mode PAD is always <SP> |
GTM>do ^fixedex fixedex; zprint ^fixedex set file="fix.txt" open file:(newversion:fixed:recordsize=4) use file write "Hello, World",! close file set file="fixnowrap.txt" open file:(newversion:fixed:recordsize=4:nowrap) use file write "Hel",! write "lo, World",! ; This writes only 'lo, ' close file zsystem ("more fix*.txt") zsystem ("od -cb fix.txt") zsystem ("od -cb fixnowrap.txt") quit :::::::::::::: fix.txt :::::::::::::: Hello, World :::::::::::::: fixnowrap.txt :::::::::::::: Hel lo, 0000000 H e l l o , W o r l d 110 145 154 154 157 054 040 127 157 162 154 144 0000014 0000000 H e l l o , 110 145 154 040 154 157 054 040 0000010
GTM>zprint ^gtmcp gtmcp ; Copy a binary file using GT.M new dest,line,max,src if 2>$length($zcmdline," ") write "$gtm_dist/mumps -r source target",! set dest=$piece($zcmdline," ",2) set src=$piece($zcmdline," ",1) set max=1024*1024 ; the maximum GT.M string size open src:(readonly:FIXED:WRAP:CHSET="M") ; open dest:(newversion:FIXED:WRAP:CHSET="M") ; use FIXED format because it does not insert carriage control characters after $X reaches its maximum value. for use src read line#max quit:$zeof use dest write line close src use dest set $x=0 close dest quit
GROUP=expr Applies to: SOC(LOCAL) SD FIFO
In order to modify file security, the user who issues the OPEN must have ownership.
open "test52.txt":(append:group="rw")
![]() | Note |
---|---|
ICHSET is a deviceparameter of both the OPEN and USE commands. As ICHSET can change the character set of an already OPENed device, it can help deal with binary data intermixed with character data. |
Applies to: SD, PIPE, and FIFO
For more information, refer to the description of KEY deviceparameter of OPEN or USE.
Performs a REWIND on input when $PRINCIPAL identifies a device that supports REWIND. Use this deviceparameter with $PRINCIPAL when redirected from a file. For FIFO or PIPE devices, REWIND only sets $X, $Y, and $ZEOF to zero. For more information, refer to a??REWINDa??.
![]() | Note |
---|---|
The IOERROR setting is associated with sockets while EXCEPTION is associated with the SOCKET device. In other words, IOERROR can be turned on or off for each of the sockets associated with a SOCKET device but there is only one EXCEPTION value which is used for all the sockets. |
open sock:(connect=host_":"_port_":TCP":delim=$char(13,10):ioerror="TRAP")::"SOCKET"
Applies to: SD, PIPE, and FIFO
![]() | Note |
---|---|
Encrypted files must be written and read sequentially from the beginning (including the Byte Order Marker for UTF files); GT.M supports READ and WRITE operations at arbitrary locations in a file only for unencrypted files. |
export LD_LIBRARY_PATH=/usr/local/lib export GNUPGHOME=$PWD/mygnupg $gtm_dist/plugin/gtmcrypt/gen_keypair.sh mykeypair@gtm Keymaster $gtm_dist/plugin/gtmcrypt/gen_sym_key.sh 0 Sunday.key $gtm_dist/plugin/gtmcrypt/gen_sym_key.sh 0 Monday.key $gtm_dist/plugin/gtmcrypt/gen_sym_key.sh 0 Tuesday.key $gtm_dist/plugin/gtmcrypt/gen_sym_key.sh 0 Wednesday.key $gtm_dist/plugin/gtmcrypt/gen_sym_key.sh 0 Thursday.key $gtm_dist/plugin/gtmcrypt/gen_sym_key.sh 0 Friday.key $gtm_dist/plugin/gtmcrypt/gen_sym_key.sh 0 Saturday.key echo -n "Enter password for gtm_passwd";export gtm_passwd="`$gtm_dist/plugin/gtmcrypt/maskpass|cut -f 3 -d " "`" export gtmcrypt_config=mygtmcryptfile cat mygtmcryptfile files: { CustomerReportKey1: "Sunday.key"; CustomerReportKey2: "Monday.key"; CustomerReportKey3: "Tuesday.key"; CustomerReportKey4: "Wednesday.key"; CustomerReportKey5: "Thursday.key"; CustomerReportKey6: "Friday.key"; CustomerReportKey7: "Saturday.key"; }; $gtm_dist/mumps -dir GTM>zprint ^encrfile encrfile set now=$horolog set timestamp=$zdate(now,"YYYYMMDDAM1260SS") set dayofweek=$zdate(now,"DAY","","1,2,3,4,5,6,7") set file="Customers"_timestamp_".log" open file:(newversion:key="CustomerReportKey"_dayofweek_" "_timestamp) use file write "Customer Report - Page 1",! close file write "IV : ",timestamp,!,"Key : CustomerReportKey"_dayofweek GTM>do ^encrfile IV : 20140911AM042419 Key : CustomerReportKey5 GTM>zprint ^readencrfile readencrfile(key,iv) set file="Customers"_iv_".log" open file:(key=key_" "_iv) use file for read data use $principal write data,! use file quit:$zeof close file GTM>do ^readencrfile("CustomerReportKey5","20140911AM042419") Customer Report - Page 1 GTM>
MOREREADTIME=intexpr Applies to: SOC
If an interval is specified, the SOCKET device always uses the specified interval and doesn't adjust dynamically. This applies to any SOCKET READ. For more information on implementing SOCKET READ, refer to a??Socket Read Operationa??.
If a SOCKET READ is not subject to any of the defined terminating conditions, it terminates either after it has at least one character followed by an interval with no new packets, or reading 1,048,576 bytes.
If you use the MOREREADTIME behavior, bear in mind that:
Usually, it is more efficient and responsive for an application to wait and process input in larger chunks. Therefore, a larger value for MOREREADTIME can bring larger chunks of input to the application. However, large values may make for sluggish response.
A short value for MOREREADTIME may consume considerable CPU cycles, especially on a lightly loaded system.
The maximum value of MORETREADTIME is 999 (basically 1 second). Never set MOREREADTIME to 0 as it causes excessive CPU "spinning".
Example:
Use tcpdev:morereadtime=200
This example specifies that all READs for socket device tcpdev must wait for 200 milliseconds for input.
NEWVERSION Applies to: SD FIFO SOC(LOCAL)
GTM>file1="foo.txt" GTM>open file1:newversion:recordsize=5000 GTM>
This example creates a new version of sequential file foo.txtwith RECORDSIZE of 5000 bytes.
GTM>set delim=$c(13) GTM>set tcpdev="server$"_$j,timeout=30 GTM>open tcpdev:(LISTEN="local.socket"_":LOCAL":delim=$c(13):attach="server":newversion):timeout:"SOCKET"
OCHSET=expr Applies to: All devices
![]() | Note |
---|---|
OCHSET is a deviceparameter of both the OPEN and USE commands. As OCHSET can change the character set of an already OPENed device, it can help deal with binary data intermixed with character data. |
GTM>SET file1="mydata.out" GTM>SET expr="UTF-16LE" GTM>OPEN file1:(ochset=expr) GTM>SET DS=$CHAR($$FUNC^%HD("0905"))_$CHAR($$FUNC^%HD("091A")) GTM>SET DS=DS_$CHAR($$FUNC^%HD("094D"))_$CHAR($$FUNC^%HD("091B"))_$CHAR($$FUNC^%HD("0940")) GTM>USE file1 WRITE DS,! GTM>CLOSE file1
Applies to: SD, PIPE, and FIFO
For more information, refer to the description of KEY deviceparameter of OPEN or USE.
KEEPALIVE a non zero value enables SO_KEEPALIVE. A zero value disables SO_KEEPALIVE. KEEPCNT sets the TCP_KEEPCNT socket value. KEEPIDLE sets the TCP_KEEPIDLE socket value. KEEPINTVL sets the TCP_KEEPINTVL socket value. SNDBUF sets the size of the socket's network send buffer (SO_SNDBUF) in bytes.
OPEN dev:(LISTEN="1234:TCP":OPTIONS="KEEPALIVE=1,KEEPIDLE=50)::"SOCKET"
This enables SO_KEEPALIVE and sets TCP_KEEPIDLE to 50 seconds.
![]() | Note |
---|---|
Please review the man page for setsockopt for more information on the use of these options. On Linux, "man 7 socket" and "man 7 tcp" provide additional information. |
Performs a REWIND on output when $PRINCIPAL identifies a device that supports REWIND. Use this deviceparameter with $PRINCIPAL when redirected to a file. For FIFO or PIPE devices, REWIND only sets $X, $Y, and $ZEOF to zero. For more information, refer to a??REWINDa??.
OWNER=expr Applies to: SOC(LOCAL) SD FIFO
To modify file security, the user who issues the OPEN must have ownership.
open "test49.txt":(newversion:owner="rw":group="rw":world="rw")
This example opens a new version of test49.txt with Read Write acess for the owner.
PAD=expr Applies to: SD FIFO PIPE
![]() | Note |
---|---|
In all UTF-16 character sets, RECORDSIZE must be even and PAD bytes occupy two bytes with the high order byte zero. |
GTM>do ^padexample padexample zprint ^padexample set a="a,>>e|?e??a??eJPY?c?-c??a??c??a??a13a??" set encoding="UTF-8" set filename="bom"_encoding_".txt" open filename:(newversion:fixed:record=8:pad=66:chset=encoding) use filename write a close filename halt $ cat bomUTF-8.txt a,>>e|?BBe??a??BBeJPY?c?-BBc??a??BBc??a??BBa13a?? $ od -tcd1 bomUTF-8.txt 0000000 344 270 273 350 246 201 B B 351 233 250 345 234 250 B B -28 -72 -69 -24 -90 -127 66 66 -23 -101 -88 -27 -100 -88 66 66 0000020 350 245 277 347 217 255 B B 347 211 231 345 201 234 B B -24 -91 -65 -25 -113 -83 66 66 -25 -119 -103 -27 -127 -100 66 66 0000040 347 225 231 345 234 250 B B 345 271 263 345 216 237 -25 -107 -103 -27 -100 -88 66 66 -27 -71 -77 -27 -114 -97 32 32
OPEN p:(COMM="(cd; pwd)":WRITEONLY)::"PIPE"
which could be specified without a PARSE error as:
OPEN p:(COMM="cd; pwd":WRITEONLY)::"pipe"
This restriction does not include parentheses embedded in character strings as in:
OPEN p:(COMM="echo ""(test)""":WRITEONLY)::"pipe"
The following are examples of valid OPEN commands using PARSE:
OPEN a:(COMM="tr e j | echoback":STDERR=e:exception="g BADOPEN":PARSE)::"PIPE" OPEN a:(SHELL="/usr/local/bin/tcsh":COMM="/bin/cat |& nl":PARSE)::"PIPE" OPEN a:(COMM="mupip integ -file mumps.dat":PARSE)::"PIPE" OPEN a:(COMM="$gtm_dist/mupip integ -file mumps.dat":PARSE)::"PIPE" OPEN a:(COMM="nohup cat":PARSE)::"PIPE"
[NO]READONLY Applies to: SD FIFO PIPE
OPENs a device for reading only (READONLY) or reading and writing (NOREADONLY).
When GT.M encounters a WRITE directed to a file, OPENed READONLY, GT.M issues a run-time error.
By default, OPEN accesses the device or file NOREADONLY (read-write).
GTM>set filename="foo.txt" GTM>open filename:(readonly:recordsize=1048576) GTM>
RECORDSIZE=intexpr Applies to: SD FIFO PIPE
Overrides the default record size for a disk.
If the character set is not UTF-16, UTF-16LE, UTF-16BE, the default RECORDSIZE is 32K-1bytes.
REWIND Applies to: FIFO PIPE SD
REWIND positions the file pointer of a sequential disk.
For FIFO or PIPE devices, REWIND only sets $X, $Y, and $ZEOF to zero.
By default, OPEN does not REWIND.
OPEN "test40.txt":(REWIND:RECORDSIZE=70:NOWRAP)
This example opens file test40.txt and places the file pointer at the beginning of the file.
[NO]STREAM Applies to: SD FIFO PIPE
By default, records are VARIABLE, NOSTREAM.
set sd="foo.txt" open sd:(newversion:stream) use sd:(width=20:nowrap) for i=1:1:10 write " the quick brown fox jumped over the lazy dog ",$x,! use sd:(rewind:width=100) for i=1:1 use sd read x quit:$zeof use $principal write !,i,?5,x close sd quit
The output of this example is as follows:
1 the quick brown fox jumped over the lazy dog 46 2 the quick brown fox jumped over the lazy dog 46 3 the quick brown fox jumped over the lazy dog 46 4 the quick brown fox jumped over the lazy dog 46 5 the quick brown fox jumped over the lazy dog 46 6 the quick brown fox jumped over the lazy dog 46 7 the quick brown fox jumped over the lazy dog 46 8 the quick brown fox jumped over the lazy dog 46 9 the quick brown fox jumped over the lazy dog 46 10 the quick brown fox jumped over the lazy dog 46
If you change the FORMAT to VARIABLE, the same example produces the following output.
1 the quick brown fox 2 the quick brown fox 3 the quick brown fox 4 the quick brown fox 5 the quick brown fox 6 the quick brown fox 7 the quick brown fox 8 the quick brown fox 9 the quick brown fox 10 the quick brown fox
1 the quick brown fox
With STREAM, the same example produces the following output:
1 the quick brown fox jumped over the lazy dog 46 the quick brown fox jumped over the lazy dog 94 the 2 quick brown fox jumped over the lazy dog 142 the quick brown fox jumped over the lazy dog 191 the q 3 uick brown fox jumped over the lazy dog 240 the quick brown fox jumped over the lazy dog 289 the qui 4 ck brown fox jumped over the lazy dog 338 the quick brown fox jumped over the lazy dog 387 the quick 5 brown fox jumped over the lazy dog 436 the quick brown fox jumped over the lazy dog 485
SYSTEM=expr Applies to: SOC(LOCAL) SD FIFO
GTM> set perm="rwx" GTM>OPEN "test52.txt":(NEWVERSION:SYSTEM="r":GROUP=perm:WORLD=perm) GTM>ZSYSTEM "ls -la test52.txt"
-r--rwxrwx 1 user group 0 Aug 20 18:36 test52.txt GTM>
VARIABLE Applies to: SD FIFO PIPE
Specifies the VARIABLE record length format for sequential disk files.
WORLD=expr Applies to: SOC(LOCAL) SD FIFO
To modify file security, the user who issues the OPEN must have ownership.
OPEN "test51.txt":(NEWVERSION:WORLD="rw")
Z[NO]DELAY Applies to: SOC(TCP)
LOCAL sockets ignore the ZDELAY deviceparameter.
open tcpdev:(LISTEN=portno_":TCP":attach="server":zbfsize=2048:zibfsize=1024):timeout:"SOCKET"
This example opens the socket device tcpdev and allocates a buffer size of 2048 bytes.
OPEN Deviceparameters | ||||||
---|---|---|---|---|---|---|
OPEN DEVICEPARAMETER |
TRM |
SD |
FIFO | PIPE |
NULL |
SOC |
TRM: Valid for terminals and printers SD: Valid for sequential disk files FIFO: Valid for FIFOs NULL: Valid for null devices PIPE: Valid for PIPEs SOC: Valid for Socket devices | ||||||
APPEND | A |
X | A | A | A | A |
ATTACH=expr | A | A | A | A | A |
X |
CHSET=encoding | X | X | X | X | X | X |
COMMAND=expr | A | A | A | X | A | A |
CONNECT=expr | A | A | A | A | A |
X |
[NO]DELIMITER | A | A | A | A | A |
X |
[NO]EMPT[ERM] |
X | A | A | A | A | A |
EXCEPTION=expr |
X |
X |
X |
X |
X |
X |
[NO]FFLF |
|
X |
|
|
|
|
FIFO | A | A |
X | A | A | A |
[NO]FIXED | A |
X |
X | X | A | A |
[NO]FOLLOW | A |
X | A | A | A | A |
GROUP=expr | A |
X |
X | A | A | A |
ICHSET=encoding | X | X | X | X | X | X |
IKEY | X | X | X | |||
INDEPENDENT | A | A | A | X | A | A |
INREWIND | A | X | X | X | A | A |
IOERROR=expr | A | A | A | A | A |
X |
KEY | X | X | X | |||
LISTEN=expr | A | A | A | A | A |
X |
[NO]NEWVERSION | A |
X |
X | A | A | A |
OCHSET=encoding | X | X | X | X | X | X |
OKEY | X | X | X | |||
OUTREWIND | A | X | X | X | A | A |
OWNER=expr | A |
X |
X | A | A | A |
PARSE | A | A | A | X | A | A |
[NO]READONLY | A |
X |
X | X | A | A |
RECORDSIZE=intexpr | A |
X |
X | X | A | A |
REWIND | A | X | X | X | A | A |
SEEK=strexpr | A | X | A | A | A | A |
SHELL=expr | A | A | A | X | A | A |
STDERR=expr | A | A | A | X | A | A |
[NO]STREAM | A |
X | X | X | A | A |
SYSTEM=expr | A |
X |
X | A | A | A |
[NO]TRUNCATE | A |
X |
X | A | A | A |
UIC=expr | A |
X |
X | A | A | A |
VARIABLE | A |
X | X | X | A | A |
WORLD=expr | A |
X |
X | A | A | A |
[NO]WRAP |
X |
X |
X | X |
X |
X |
[NO]WRITEONLY | A | X | X | X | A | A |
ZBFSIZE | A | A | A | A | A |
X |
Z[NO]DELAY | A | A | A | A | A |
X |
Z[NO]FF | A | A | A | A | A |
X |
ZIBFSIZE | A | A | A | A | A |
X |
The USE command selects the current device for READs (input) and WRITEs (output).
The format of the USE command is:
U[SE][:tvexpr] expr[:(keyword[=expr][:...])][,...]
USE $P:(X=0:Y=$Y-1:NOECHO)
![]() | Note |
---|---|
A socket does not carry [I|O]CHSET with it while being moved. Such a socket uses the [I|O]CHSET of the device it is ATTACHed to. If there is input still buffered, this may cause unintentional consequences in the application if [I|O]CHSET changes. GT.M does not detect (or report) a change in [I|O]CHSET due to DETACH/ATTACH. |
For information on using the ATTACH with OPEN, refer to a??ATTACHa?? in the OPEN Deviceparameters section.
Enables or disables the ability to force GT.M into Direct Mode by entering <CTRL-C> at $PRINCIPAL.
If CENABLE is set, <CTRL-C> interrupts process execution. For more information on interrupt handling, refer to a??Interrupt Handlinga??.
By default, CENABLE is set. If CTRAP contains $C(3), CENABLE is disabled.
Example:
use $principal:(nocenable:ctrap="":exception="")
For more information, refer to a??CONNECTa??.
![]() | Note |
---|---|
CONNECT is not compatible with LISTEN. |
Although CONNECT can be used with USE command, FIS recommends not to use it that way, because unlike the OPEN command, there is no way to specify a timeout to the USE command. CONNECT in the USE command take a default timeout value of 0.
Example:
Refer to the "CONNECT" examples in a??Examples of OPENa??.
Enables or disables GT.M from converting lowercase input to uppercase during READs.
By default, the terminal device driver operates NOCONVERT.
use $principal:(convert) READ X
This example converts all lowercase to uppercase during READ X.
CTRAP=$CHAR(intexpr[,...]) Applies to: TRM
A <CTRL-n> enabled by CTRAP produces one of the following actions:
For more information on error handling, refer to ChapterA 13: a??Error Processinga??.
When CTRAP includes <CTRL-C>, [NO]CENABLE has no effect. CTRAPping <CTRL-C> also takes precedence over CENABLE.
expr must be a string of the following format:
![]() | Note |
---|---|
expr "ab:/:://:bc" is interpreted as four delimiters, which are "ab", ":", "/", and "bc". One socket can have 0-64 delimiters and each delimiter can contain 1-64 characters. |
![]() | Note |
---|---|
A socket can move from one device to another using DETACH/ATTACH. A socket does not carry [I|O]CHSET with it while being moved. Such a socket uses the [I|O]CHSET of the device it is ATTACHed to. If there is input still buffered, this may cause unintentional consequences in the application if [I|O]CHSET changes. GT.M does not detect (or report) a change in [I|O]CHSET due to DETACH/ATTACH. DETACH is not compatible with any other device parameters in the USE command. |
GTM>set tcp="seerv" open tcp:(listen="6321:TCP":attach="serv")::"SOCKET" GTM>zshow "D" /dev/pts/9 OPEN TERMINAL NOPAST NOESCA NOREADS TYPE WIDTH=80 LENG=24 seerv OPEN SOCKET TOTAL=1 CURRENT=0 SOCKET[0]=serv DESC=3 LISTENING PASSIVE NOTRAP PORT=6321 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER GTM>set tcp="seerv" o tcp:(listen="6322:TCP":attach="serv2")::"SOCKET" GTM>zshow "D" /dev/pts/9 OPEN TERMINAL NOPAST NOESCA NOREADS TYPE WIDTH=80 LENG=24 seerv OPEN SOCKET TOTAL=2 CURRENT=1 SOCKET[0]=serv DESC=3 LISTENING PASSIVE NOTRAP PORT=6321 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER SOCKET[1]=serv2 DESC=4 LISTENING PASSIVE NOTRAP PORT=6322 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER
At this point, the socket device "seerv" has two sockets associated with it.
The following command moves the "serv" socket to the "YGTMSOCKETPOOL" device.
GTM>use tcp:detach="serv" GTM>use 0 zshow "D" /dev/pts/9 OPEN TERMINAL NOPAST NOESCA NOREADS TYPE WIDTH=80 LENG=24 seerv OPEN SOCKET TOTAL=1 CURRENT=0 SOCKET[0]=serv2 DESC=4 LISTENING PASSIVE NOTRAP PORT=6322 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER YGTMSOCKETPOOL OPEN SOCKET TOTAL=1 CURRENT=0 SOCKET[0]=serv DESC=3 LISTENING PASSIVE NOTRAP PORT=6321 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER
GTM>set tcp2="s2" o tcp2:::"SOCKET"
This creates a new socket device.
GTM>zshow "D" /dev/pts/9 OPEN TERMINAL NOPAST NOESCA NOREADS TYPE WIDTH=80 LENG=24 s2 OPEN SOCKET TOTAL=0 CURRENT=0 seerv OPEN SOCKET TOTAL=1 CURRENT=0 SOCKET[0]=serv2 DESC=4 LISTENING PASSIVE NOTRAP PORT=6322 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER YGTMSOCKETPOOL OPEN SOCKET TOTAL=1 CURRENT=0 SOCKET[0]=serv DESC=3 LISTENING PASSIVE NOTRAP PORT=6321 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER
The following command moves the serv socket from the socketpool to the tcp2 device.
GTM>use tcp2:attach="serv" GTM>use 0 zshow "D" /dev/pts/9 OPEN TERMINAL NOPAST NOESCA NOREADS TYPE WIDTH=80 LENG=24 s2 OPEN SOCKET TOTAL=1 CURRENT=0 SOCKET[0]=serv DESC=3 LISTENING PASSIVE NOTRAP PORT=6321 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER seerv OPEN SOCKET TOTAL=1 CURRENT=0 SOCKET[0]=serv2 DESC=4 LISTENING PASSIVE NOTRAP PORT=6322 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER YGTMSOCKETPOOL OPEN SOCKET TOTAL=0 CURRENT=-1
By default, EDITING mode is disabled.
If you enable the EDITING mode, escape sequences do not terminate READs.
Enabling PASTHRU mode supersedes EDITING mode.
![]() | Note |
---|---|
M READ EDITING depends on the values of $X and $Y being correct. If the application sends its own escape sequences or control characters, which change the cursor position, it must properly update $X and $Y before doing a M READ with EDITING enabled to ensure correct formatting during input. |
Enables or disables GT.M processing of escape sequences.
By default, ESCAPE processing is disabled.
use $principal:(noescape:term=$c(13))
This example disables the escape sequence processing and set $c(13) as the line terminator.
EXCEPTION=expr Applies to: All devices
For more information on error handling, refer to ChapterA 13: a??Error Processinga??.
[NO]FILTER[=expr] Applies to: TRM SOC NULL
use tcpdev:filter="NOESCAPE"
This example removes the effect of escape sequences on the maintenance $X and $Y.
Applies to: SD, PIPE, and FIFO
For more information, refer to the description of KEY deviceparameter of OPEN.
Performs a REWIND on input when $PRINCIPAL identifies a device that supports REWIND. Use this deviceparameter with $PRINCIPAL when redirected from a file. For FIFO or PIPE devices, REWIND only sets $X, $Y, and $ZEOF to zero. For more information, refer to a??REWINDa??.
Performs a SEEK on input when $PRINCIPAL identifies a device that supports SEEK. Use this deviceparameter with $PRINCIPAL when redirected from a file. For more information, refer to a??SEEK=strexpra??.
![]() | Note |
---|---|
GT.M currently handles exception handling at device level instead of socket level. |
use sock:(ioerror="TRAP":exception="zgoto "_$zlevel_":error")
Applies to: SD, PIPE, and FIFO
For more information and an example, refer to the description of KEY deviceparameter of OPEN.
[Z]LENGTH=intexpr Applies to: TRM SOC SD FIFO PIPE NULL
Setting LENGTH to zero prevents resetting $Y to zero.
use sock:(width=80:znoff:zlength=24)
This example sets the virtual page length to 24 for socket device sock.
For more information, refer to a??LISTENa??.
Example:
GTM>set tcp="seerv" open tcp:(listen="6321:TCP":attach="serv")::"SOCKET" GTM>use tcp:listen="6322:TCP" GTM>use 0 zshow "D" /dev/pts/9 OPEN TERMINAL NOPAST NOESCA NOREADS TYPE WIDTH=80 LENG=24 seerv OPEN SOCKET TOTAL=2 CURRENT=1 SOCKET[0]=serv DESC=3 LISTENING PASSIVE NOTRAP PORT=6321 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER SOCKET[1]=h12185825450 DESC=4 LISTENING PASSIVE NOTRAP PORT=6322 ZDELAY ZBFSIZE=1024 ZIBFSIZE=87380 NODELIMITER
Applies to: SD, PIPE, and FIFO
For more information, refer to the description of KEY deviceparameter of OPEN.
KEEPALIVE a non zero value enables SO_KEEPALIVE. A zero value disables SO_KEEPALIVE. KEEPCNT sets the TCP_KEEPCNT socket value. KEEPIDLE sets the TCP_KEEPIDLE socket value. KEEPINTVL sets the TCP_KEEPINTVL socket value. SNDBUF sets the size of the socket's network send buffer (SO_SNDBUF) in bytes.
USE dev:OPTIONS="KEEPALIVE=1,KEEPIDLE=50"
This enables SO_KEEPALIVE and sets TCP_KEEPIDLE to 50 seconds.
![]() | Note |
---|---|
Please review the man page for setsockopt for more information on the use of these options. On Linux, "man 7 socket" and "man 7 tcp" provide additional information. |
Performs a REWIND on output when $PRINCIPAL identifies a device that supports REWIND. Use this deviceparameter with $PRINCIPAL when redirected to a file. For FIFO or PIPE devices, REWIND only sets $X, $Y, and $ZEOF to zero. For more information, refer to a??REWINDa??.
Performs a SEEK on output when $PRINCIPAL identifies a device that supports SEEK. Use this deviceparameter with $PRINCIPAL when redirected to a file. For more information, refer to a??SEEK=strexpra??.
[NO]TTSYNC must be used with [NO]PASTHRU to control XON/XOFF handling.
REWIND Applies to: FIFO PIPE SD
REWIND places the file pointer to the beginning of the file.
For FIFO and PIPE devices, REWIND only sets $X, $Y, and $ZEOF to zero.
By default, USE does not REWIND.
REWIND on redirected output for $PRINCIPAL is the same as OUTREWIND.
![]() | Note |
---|---|
SOCKET is compatible with DELIMITER only. |
For a usage example, refer to the socketexamplemulti2.m in the SectionA : a??Socket Device Examplesa??.
[NO]TERMINATOR[=expr] Applies to: TRM
You can define any control character as a terminator, but they are all single character.
GTM> USE $P:TERM=$C(26,13,11,7)
This example enables the ASCII characters <SUB>, <CR>, <VT> and <BEL> as READ terminators.
Enables or disables recognition of XON/XOFF for terminal output.
![]() | Note |
---|---|
A terminal may have its own handling of XON/XOFF, controlled by a set-up mode or by switches. If an application requires program recognition of <CTRL-S> and <CTRL-Q>, the terminals may require reconfiguration. |
[Z]WIDTH=intexpr Applies to: TRM SOC NULL SD FIFO PIPE
For SD and SOC which support 1MiB strings, you can specify WIDTH up to 1,048,576.
Positions the cursor to a horizontal row on the terminal.
The Y deviceparameter does not change the cursor column or update $X.
USE Deviceparameters | ||||||
---|---|---|---|---|---|---|
USE DEVICEPARAMETER |
TRM |
SD |
FIFO | PIPE |
NULL |
SOC |
TRM: Valid for terminals and printers SD: Valid for sequential files FIFO: Valid for FIFOs PIPE: Valid for PIPE devices NULL: Valid for null devices SOC: Valid for socket devices | ||||||
ATTACH | A | A | A | A | A |
X |
CANONICAL |
X | A | A | A | A | A |
[NO]CENABLE |
X | A | A | A | A | A |
[I|O]CHSET |
X |
X |
X |
X |
X |
X |
CLEARSCREEN |
X | A | A | A | A | A |
CONNECT | A | A | A | A | A |
X |
[NO]CONVERT |
X | A | A | A | A | A |
CTRAP=expr |
X | A | A | A | A | A |
[NO]DELIMITER | A | A | A | A | A |
X |
DETACH=expr | A | A | A | A | A |
X |
DOWNSCROLL |
X | A | A | A | A | A |
[NO]ECHO |
X | A | A | A | A | A |
[NO]EMPTERM |
X | A | A | A | A | A |
ERASELINE |
X | A | A | A | A | A |
[NO]ESCAPE |
X | A | A | A | A | A |
EXCEPTION=expr |
X |
X |
X |
X |
X |
X |
[NO]FFLF |
|
X |
|
|
|
|
[NO]FILTER[=expr] |
X | A | A | A |
X |
X |
FLUSH |
X | A | A | A | A |
X |
[NO]FOLLOW | A |
X | A | A | A | A |
[NO]HOSTSYNC |
X | A | A | A | A | A |
[NO]HUPENABLE |
X | A | A | A | A |
X |
IKEY | A | X | X | X | A | A |
INREWIND | A | X | X | X | A | A |
INSEEK | A | X | A | A | A | |
IOERROR | A | A | A | A | A |
X |
KEY | A | X | X | X | A | A |
[Z]LENGTH=expr |
X |
X |
X |
X |
X |
X |
LISTEN | A | A | A | A | A |
X |
OKEY | A | X | X | X | A | A |
OUTREWIND | A | X | X | X | A | |
OUTSEEK | A | X | A | A | A | |
[NO]PASTHRU |
X | A | A | A | A | A |
REWIND | A | X | X | X | A | A |
SEEK=strexpr | A | X | A | A | A | A |
SOCKET | A | A | A | A | A |
X |
TERMINATOR[=expr] |
X | A | A | A | A | A |
[NO]TRUNCATE | A |
X | A | A | A | A |
[NO]TYPEAHEAD |
X | A | A | A | A | A |
UPSCROLL |
X | A | A | A | A | A |
[Z]WIDTH=intexpr |
X |
X |
X | X |
X |
X |
[NO]WRAP |
X |
X |
X |
X |
X |
X |
X=intexpr |
X | A | A | A |
X | A |
Y=intexpr |
X | A | A | A |
X | A |
ZBFSIZE | A | A | A | A | A |
X |
Z[NO]DELAY | A | A | A | A | A |
X |
Z[NO]FF | A | A | A | A | A |
X |
ZIBFSIZE | A | A | A | A | A |
X |
The format of the READ command is:
R[EAD][:tvexpr] glvn|*glvn|glvn#intexpr|strlit|fcc[,...]
The READ commands adjust $X and $Y, based on the length of the input read.
GTM> READ *X A GTM> WRITE X 65
GTM>Set filename="mydata.out"; assume that mydata.out contains "a,>>e|?e??a??eJPY?c?-c??a??c??a??a13a??". GTM>Open filename:(readonly:ichset="UTF-16LE") GTM>Use filename GTM>Read *x GTM>Close filename GTM>Write $char(x) a,>>
The WRITE command transfers a character stream specified by its arguments to the current device.
The format of the WRITE command is:
W[RITE][:tvexpr] expr|*intexpr|fcc[,...]
![]() | Note |
---|---|
If $X is less than WIDTH, WRITE ! writes WIDTH - $X spaces. |
For more information, see the sections on specific I/O devices.
The CLOSE command breaks the connection between a process and a device.
The format of the CLOSE command is:
C[LOSE][:tvexpr] expr[:(keyword[=expr][:...])][,...]
If the device being CLOSEd is $IO, GT.M implicitly USEs $PRINCIPAL. GT.M ignores CLOSE $PRINCIPAL.
CLOSE SD:RENAME=SD_".SAV"
This closes the device and, if it is a disk file, renames it to have the type .SAV.
CLOSE SOCKDEV:(SOCKET="LOCALSOCK1":DELETE)
EXCEPTION=expr Applies to: All devices
For more information on error handling, refer to ChapterA 13: a??Error Processinga??.
GROUP=expr Applies to: SOC(LOCAL), SD, FIFO
In order to modify file security, the user who issues the CLOSE must have ownership.
By default, CLOSE does not modify the permissions on an existing file.
OWNER=expr Applies to: SOC(LOCAL) SD FIFO
In order to modify file security, the user who issues the CLOSE must have ownership.
By default, CLOSE does not modify the permissions on an existing file.
SYSTEM=expr Applies to: SOC(LOCAL) SD FIFO
By default, CLOSE does not modify the permissions on an existing file.
CLOSE Deviceparameters | ||||
---|---|---|---|---|
CLOSE DEVICEPARAMETER |
TRM |
SD |
FIFO |
SOC |
SD: Valid for sequential disk files TRM: Valid for terminals and printers FIFO: Valid for FIFOs NULL: Valid for NULL devices SOC: Valid for Socket devices | ||||
A |
X |
X |
X | |
A |
X |
X | X | |
X |
X |
X |
X | |
A |
X |
X | A | |
A |
X |
X | A | |
A |
X |
X | A | |
A |
X |
X | A | |
A |
X | X | A | |
A | A | A |
X | |
A |
X |
X | A | |
A |
X |
X | A | |
A |
X |
X | A |
![]() | Note |
---|---|
Since EXCEPTION is the only CLOSE deviceparameter that applies to NULL, the NULL device column is not shown in the table above. |
The following table lists all of the deviceparameters and shows the commands to which they apply.
Deviceparameter Summary | |||
---|---|---|---|
DEVICEPARAMETER |
OPEN |
USE |
CLOSE |
APPEND |
X | A | A |
ATTACH | A |
X | A |
BLOCKSIZE=intexpr |
X | A | A |
[NO]CENABLE | A |
X | A |
CLEARSCREEN | A |
X | A |
CONNECT |
X |
X | A |
[NO]CONVERT | A |
X | A |
CTRAP | A |
X | A |
DELETE | A | A |
X |
[NO]DELIMITER |
X |
X | A |
[NO]DESTROY | X | ||
DETACH | A |
X | A |
DOWNSCROLL | A |
X | A |
[NO]ECHO | A |
X | A |
ERASELINE | A |
X | A |
[NO]ESCAPE | A |
X | A |
EXCEPTION=expr |
X |
X |
X |
[NO]FFLF |
X |
X | A |
[NO]FILTER[=expr] | A |
X | A |
[NO]FIXED |
X | A | A |
FLUSH | A |
X | A |
GROUP=expr |
X |
X |
X |
KEY |
X |
X |
|
IKEY |
X |
X |
|
IOERROR=expr |
X |
X | A |
[NO]HOSTSYNC | A |
X | A |
[NO]HUPENABLE | A |
X | A |
[Z]LENGTH=intexpr | A |
X | A |
NEWVERSION |
X | A | A |
OKEY |
X |
X |
|
OWNER=expr |
X |
X |
X |
[NO]PASTHRU | A |
X | A |
[NO]RCHK |
X |
X | A |
[NO]READONLY |
X | A | A |
RECORDSIZE=intexpr |
X | A | A |
RENAME=expr | A | A |
X |
REPLACE=expr | A | A |
X |
[NO]RETRY |
X |
X | A |
REWIND |
X |
X |
X |
SKIPFILE=intexpr | A |
X | A |
SOCKET | A |
X |
X |
SPACE=intexpr | A |
X |
X |
[NO]STREAM |
X | A | A |
SYSTEM=expr |
X | A |
X |
TERMINATOR=expr | A |
X | A |
TIMEOUT=expr | A |
| X |
[NO]TRUNCATE |
X |
X | A |
[NO]TTSYNC | A |
X | A |
[NO]TYPEAHEAD | A |
X | A |
UIC=expr |
X | A |
X |
UPSCROLL | A |
X | A |
VARIABLE |
X | A | A |
[Z]WIDTH=intexpr | A |
X | A |
WORLD=expr |
X | A |
X |
[Z][NO]WRAP |
X |
X | A |
WRITELB=expr | A |
X | A |
X=intexpr | A |
X | A |
Y=intexpr | A |
X | A |
ZBFSIZE |
X |
X | A |
Z[NO]DELAY |
X |
X | A |
Z[NO]FF |
X |
X | A |
ZIBFSIZE |
X |
X | A |
LISTEN=expr |
X |
X | A |