home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
prgramer
/
rexx
/
rxsock
/
rxsock.doc
< prev
next >
Wrap
Text File
|
1993-03-10
|
16KB
|
453 lines
rxSock
Rexx Function Package for TCP/IP Sockets for OS/2 2.0
by Patrick Mueller
(c) Copyright International Business Machines Corporation 1993.
All rights Reserved.
----------------------------------------------------------------------
what is rxSock?
----------------------------------------------------------------------
rxSock is a REXX function package providing access to the OS/2
TCP/IP socket API as provided by the IBM TCP/IP product, version
1.2.1.
The function reference below is minimalistic. It is assumed you
are already familiar with the basic socket APIs, and can reference
the OS/2 specific ones. A widely available book on the basic socket
APIs is "Internetworking with TCP/IP Volume I: Principals, Protocols,
and Architecture" by Douglas Comer.
This function package requires the OS/2 TCP/IP product, version 1.2.1
or higher.
----------------------------------------------------------------------
installation and removal
----------------------------------------------------------------------
The rxSock rexx function package is contained in the file rxSock.dll.
This file needs to be placed in a directory along your LIBPATH. To get
access to the functions in the rxSock function package, execute the
following rexx code:
rc = RxFuncAdd("SockLoadFuncs","rxSock","SockLoadFuncs")
rc = SockLoadFuncs()
To unload the DLL, you should first call the SockDropFuncs()
function, then exit all CMD.EXE shells. After exiting all the
command shells, the DLL will be dropped by OS/2 and can be deleted
or replaced.
----------------------------------------------------------------------
Parameters and Return Values
----------------------------------------------------------------------
Return values for most functions are the same as the C equivalents,
unless otherwise noted.
There are a number of standard parameters types referenced in the
function reference.
o socket
This is a socket value. It is an integral number.
o address
This is the 'stem' of a stemmed variable with the following values:
o address.family
should always be "AF_INET"
o address.port
a port number
o address.addr
a dotted decimal address, or where appropriate, "INADDR_ANY"
When this parameter is needed you should set it the name of a stem
variable for the function to set (or that the function will read
from). For example, if you passed the string "xxx.!" as a
parameter, the variables
"xxx.!family",
"xxx.!port", and
"xxx.!addr"
will be set by the function, or queried by the function.
o dotAddress
the standard dotted decimal address. For example, the string
"9.23.19.63" is a valid address.
o host
This is the 'stem' of a stemmed variable with the following values:
o host.name
the standard name of the host
o host.alias.0
number of aliases for this host
o host.alias.1
First alias for this host
o host.alias.n
n'th alias for this host
o host.addrtype
should always be "AF_INET"
o host.addr
a dotted decimal address
When this parameter is needed you should set it the name of a stem
variable for the function to set (or that the function will read
from). For example, if you passed the string "xxx.!" as a
parameter, the variables
"xxx.!name",
"xxx.!alias.0",
"xxx.!alias.1" ... "xxx.!alias.n",
"xxx.!addrtype"
"xxx.!addr"
will be set by the function, or queried by the function.
----------------------------------------------------------------------
Special note on stemmed variables
----------------------------------------------------------------------
The address and host type of parameters are stemmed variable names.
Traditionally, you would pass a string like "addr." as a parameter,
and expect to have the variables addr.family, addr.port, and addr.addr
set by the function. In the examples above though, I showed using
a stem like "addr.!". The exclamation point helps to distinguish the
tail values, so they won't get mis-used as normal variables. For
instance, look at the following code:
port = 923
sNew = SockAccept(sOld,"addr.")
say addr.port
You might expect the say statement to write the port number of the
accept'ed socket. Instead it writes the value of the variable
addr.923, since the port variable is SET to a value.
Since you probably don't normally use exclamation points in your
variables, it's unlikely that you will be using the variable "!port"
in your program.
Also note, some folk prefer other characters, including "_", "0", and
"1" (the digits are allowed to prefix tail values and are very
secure against this kind of accidental misuse - I don't use them
because the characters are hard to distinguish from O, I, and l.
----------------------------------------------------------------------
Variables set
----------------------------------------------------------------------
o errno
The errno variable is set after every rxSock function call. It
will have one of the following values (or a numeric value if the
number isn't one of these values, probably indicating an errno
value the compiler that the tcp/ip product was written in). Note
the value is set even if the function that was called does not
neccessarily set the variable, in which case the value has no
meaning.
"EWOULDBLOCK"
"EINPROGRESS"
"EALREADY"
"ENOTSOCK"
"EDESTADDRREQ"
"EMSGSIZE"
"EPROTOTYPE"
"ENOPROTOOPT"
"EPROTONOSUPPORT"
"ESOCKTNOSUPPORT"
"EOPNOTSUPP"
"EPFNOSUPPORT"
"EAFNOSUPPORT"
"EADDRINUSE"
"EADDRNOTAVAIL"
"ENETDOWN"
"ENETUNREACH"
"ENETRESET"
"ECONNABORTED"
"ECONNRESET"
"ENOBUFS"
"EISCONN"
"ENOTCONN"
"ESHUTDOWN"
"ETOOMANYREFS"
"ETIMEDOUT"
"ECONNREFUSED"
"ELOOP"
"ENAMETOOLONG"
"EHOSTDOWN"
"EHOSTUNREACH"
"ENOTEMPTY"
o h_errno
The h_errno variable is set after every rxSock function call. It
will have one of the following values (or a numeric value if the
number isn't one of these values). Note the value is set even if
the function that was called does not neccessarily set the
variable, in which case the value has no meaning.
"HOST_NOT_FOUND"
"TRY_AGAIN"
"NO_RECOVERY"
"NO_ADDRESS"
----------------------------------------------------------------------
Functions Reference
----------------------------------------------------------------------
Each of the functions below correspond to their like-named C functions
available in the OS/2 TCP/IP socket library (except SockLoadFuncs and
SockDropFuncs).
-------------------------------------------------------------------
SockLoadFuncs
-------------------------------------------------------------------
rc = SockLoadFuncs()
Loads all the functions in the rxSock package.
If ANY parameters are passed to this function, it will bypass
the program/author/copyright information normally displayed.
All parameters are ignored (except to determine whether or not
to bypass displaying the information).
-------------------------------------------------------------------
SockDropFuncs
-------------------------------------------------------------------
rc = SockDropFuncs()
Drops all the functions in the rxSock package.
-------------------------------------------------------------------
SockAccept - implements C function accept()
-------------------------------------------------------------------
socket = SockAccept(socket,address)
-------------------------------------------------------------------
SockBind - implements C function bind()
-------------------------------------------------------------------
rc = SockBind(socket,address)
-------------------------------------------------------------------
SockConnect - implements C function connect()
-------------------------------------------------------------------
rc = SockConnect(socket,address)
-------------------------------------------------------------------
SockGetHostByAddr - implements C function gethostbyaddr()
-------------------------------------------------------------------
rc = SockGetHostByAddr(dotAddress,host)
Returns 0 for success, 1 for error.
-------------------------------------------------------------------
SockGetHostByName - implements C function gethostbyname()
-------------------------------------------------------------------
rc = SockGetHostByName(nameAddress,host)
nameAddress should be the textual name of a host, for example
"pmuellr.vnet.ibm.com".
Returns 0 for success, 1 for error.
-------------------------------------------------------------------
SockGetHostId - implements C function gethostid()
-------------------------------------------------------------------
dotAddress = SockGetHostId()
-------------------------------------------------------------------
SockGetPeerName - implements C function getpeername()
-------------------------------------------------------------------
rc = SockGetPeerName(socket,address)
-------------------------------------------------------------------
SockGetSockName - implements C function getsockname()
-------------------------------------------------------------------
rc = SockGetSockName(socket,address)
-------------------------------------------------------------------
SockGetSockOpt - implements C function getsockopt()
-------------------------------------------------------------------
value = SockGetSockOpt(socket,option)
Not yet implemented.
-------------------------------------------------------------------
SockInit - implements C function sock_init()
-------------------------------------------------------------------
rc = SockInit()
-------------------------------------------------------------------
SockIoctl - implements C function ioctl()
-------------------------------------------------------------------
rc = SockIoctl(socket,cmd,data)
Not yet implemented.
-------------------------------------------------------------------
SockListen - implements C function listen()
-------------------------------------------------------------------
rc = SockListen(socket,backlog)
-------------------------------------------------------------------
SockRecv - implements C function recv()
-------------------------------------------------------------------
rc = SockRecv(socket,var,len<,flags>)
var is the name of a rexx variable the data should be received into.
len is the maximum amount of data to read.
flags can be one of "MSG_OOB" or "MSG_PEEK".
Returns the return code from the recv() function.
-------------------------------------------------------------------
SockSelect - implements C function select()
-------------------------------------------------------------------
ready = SockSelect(reads,writes,excepts)
Not yet implemented. Looking for ideas on what the parameters
and return values should be.
-------------------------------------------------------------------
SockSend - implements C function send()
-------------------------------------------------------------------
rc = SockSend(socket,data<,flags>)
data is a string of text to be sent on the sock.
flags may be one of"MSG_OOB" or "MSG_DONTROUTE".
Returns the return code from the send() function.
-------------------------------------------------------------------
SockSetSockOpt - implements C function setsockopt()
-------------------------------------------------------------------
rc = SockSetSockOpt(socket,opt,value)
Not yet implemented.
-------------------------------------------------------------------
SockShutDown - implements C function shutdown()
-------------------------------------------------------------------
rc = SockShutDown(socket,how)
-------------------------------------------------------------------
SockSocket - implements C function socket()
-------------------------------------------------------------------
socket = SockSocket(domain,type,protocol)
domain must be "AF_INET".
type may be one of "SOCK_STREAM", "SOCK_DGRAM", or "SOCK_RAW"
protocol may be one of "IPPROTO_UDP", "IPPROTO_TCP", or "0"
-------------------------------------------------------------------
SockSoClose - implements C function soclose()
-------------------------------------------------------------------
rc = SockSoClose(socket)
----------------------------------------------------------------------
Utilities Provided
----------------------------------------------------------------------
killsock.cmd
------------
This program takes socket numbers and closes them. Useful for
terminating a stubborn server, or cleaning up after accidents.
Use "netstat -s" to get a list of currently open sockets.
rnr.cmd
-------
A very basic news reader. Used to demonstrate a fairly complex
application using rxSock functions.
test_h.cmd
----------
A test program testing address to hostname conversions.
test_c.cmd
test_s.cmd
----------
These program are test client/server programs. Start test_s.cmd
in one session, and then test_c.cmd in another. The programs
exchange data and print some timing information before quitting.
The server and client can run across two different hosts. Pass
the host name of the server as a parameter to test_c.cmd
----------------------------------------------------------------------
Signal Handling
----------------------------------------------------------------------
Due to the many interfaces involved in the rxSock package (REXX,
tcp/ip), it's hard to determine who is handling signal exceptions,
and if they are being handled appropriately. Signal exceptions
are generated for Ctrl-C, Ctrl-Break keys, or having DosKillProcess()
run specifying the current process.
rxSock can provide it's own signal exception handling, so that you can
break out of blocked function calls. Currently this is implemented by
returning an 'invalid' return code from the external function. REXX
interprets this as an 'incorrect call to routine', so don't be too
suprised when you see this as the result of pressing ctrl-c or ctrl-break
while one of the rxSock functions is executing.
The SockException() function can be used to change and query this
behaviour. Invoking SockException() with no parameters returns
"ON" or "OFF" indicating whether exceptions are handled by rxSock
("ON") or not ("OFF"). The string "ON" or "OFF" can be passed to
SockException to change the behaviour. The previous value is
returned in this case.
The initial value is "OFF", meaning rxSock does nothing special for
signal exception handling (leaving it up to REXX and/or tcp/ip and/or
CMD.EXE). This is a process-persistant value, so calling
SockException() will cause the setting to be used in the next REXX macro
using rxSock running under the same CMD.EXE process.
The default value ("OFF") works fine for me on OS/2 2.0 with the
Service Pack installed.