Open System Services Porting Guide (G06.24+, H06.03+)

Table Of Contents
Porting or Migrating Sockets Applications
Open System Services Porting Guide520573-006
11-7
Compiling Native and TNS OSS Programs
Marking existing sockets as nonblocking using the fcntl() function
Performing reads or writes on any sockets that are ready
Handling the errno value EWOULDBLOCK and retrying the input or output
later when necessary
Table 11-2 summarizes the differences between nonblocking (OSS) and nowait
(Guardian) sockets I/O.
Compiling Native and TNS OSS Programs
To compile native OSS applications, you must use the TNS/R or TNS/E native mode
c89 compiler. The following OSS shell command compiles and links the native sockets
program nsock.c:
c89 -o nsock nsock.c -l c -D _XOPEN_SOURCE_EXTENDED = 1
-D _TANDEM_SOURCE
To compile G-series TNS OSS applications, you must use the TNS c89 compiler. TNS
AF_INET sockets applications must be linked with the shared sockets library
libinet.a, which resides in /usr/lib. The following OSS shell command compiles
the TNS sockets program nnsock.c:
/nonnative/usr/c89 -o nnsock nnsock.c -l inet -l c
-D _XOPEN_SOURCE_EXTENDED = 1 -D _TANDEM_SOURCE
See the C/C++ Programmer’s Guide and the nld Manual, the ld Manual, or the eld
Manual for more information on compiling and linking native C and C++ programs.
Table 11-2. Major Differences Between OSS and Guardian Sockets Input/Output
OSS Nonblocking I/O Guardian Nowait I/O
A socket is created with socket() and
fcntl(fd, F_SETFL,O_NONBLOCK)
makes the socket nonblocking.
A socket is created as waited with
socket()
or as a nowait socket with socket_nw().
When a socket I/O call is made, control is
returned immediately to the application.
Either the operation is performed or the
error
EWOULDBLOCK is returned.
When a socket I/O call is made, control is
returned immediately to the application. The
operation is performed concurrently with the
application execution. The status of the I/O
completion must be checked with a Guardian
procedure call.
A socket operation requires a single buffer.
For example, four recv() calls require one
buffer.
Every socket operation requires a separate
preallocated buffer. For example, four recv()
calls require four buffers.
The
select() function waits for
specified file descriptors for the next
opportunity to issue a nonblocking I/O call.
AWAITIOX operates on file numbers rather
than file descriptors. FILE_COMPLETE_ allows
waiting for completion on file numbers and on
the readiness of file descriptors;
FILE_COMPLETE_ therefore acts like a
combination of AWAITIOX and select().